library(foreign)
## Warning: package 'foreign' was built under R version 3.3.2
r=read.dta("C:/Data/dataR5a.dta")
r1 <- subset(r, cost_inc>1 )
attach(r1)
r1$logC1=log10(r1$cost_inc)
r1$logC2=r1$cost_inc/1000
r1$highper[cost_inc<=62000] <- 0
r1$highper[cost_inc>62000] <- 1
r1$b16a[b16a == 5] <- 0
r1$freeEn[c9==1] <- 1
r1$freeEn[c9>1] <- 0
r1$h1[h1== 1] <- 1
r1$h1[h1== 2] <- 0
r1$c7ad[c7== 2] <- 0
r1$c7ad[c7== 1] <- 1
r1$c7ad[is.na(r1$c7)] <- 0
r1$ant[c5==1& c5==2 & c5==7 & c5==8 & c5==9] <- 0
r1$ant[c5==3|c5==4|c5==5] <- 1
r1$ant[is.na(r1$c5)] <- 0
r1$p1=r1$label1+r1$freeEn+r1$ant+r1$c7ad
r1$p[r1$p1==0] <- 0
r1$p[r1$p1==1] <- 1
r1$p[r1$p1>=2] <- 2
r1$wtp[cost_inc >=1] <- 0
r1$wtp[is.na(r1$wtp)] <- 1
newdata2=r1
attach(newdata2 )
## The following objects are masked from r1:
##
## a, a1, advice, ag, age_group, anticam, b1, b10, b10a1, b10a2,
## b10a3, b10a4, b10a5, b10a6, b10a7, b11, b11a, b11a2, b11a3,
## b12, b12a, b13, b14, b15, b16, b16a, b17, b18, b18a, b1a,
## b1a1, b1a2, b1a3, b2, b2a1, b3, b4, b5, b5a, b6, b6_123, b6a,
## b6a1, b6a2, b6a3, b6a4, b6a5, b6a6, b6a7, b6a7a, b6b, b7, b8,
## b9, br, branch, branch1, branch2, branch3, c1, c2, c23a, c3,
## c4, c5, c6, c6a111, c7, c8, c9, clog, clog1, COST, cost_inc,
## cost1, costincrease, ct, d1, d10, d11, d1a, d2, d3, d3a, d4,
## d5, d6, d7, d8, d9, Decision, e1, e2, edu, educ1, educ2, f1,
## ghi1, ghi2, ghiro2, giadinhkoUH, group_age, group_age1, h1,
## h10a, h10a1, h10a10, h10a11, h10a11a, h10a2, h10a3, h10a4,
## h10a5, h10a6, h10a7, h10a8, h10a9, h12, h12a, h12a_1, h12log,
## h13, h2, h3, h4, h5, h6, h7, h8, h9, ha000, ict1a, ict2a,
## itc1, itc2, l1, l2, l3, l4, l5, l6, label_1, label1, label1a,
## logb7, logC, logitCost, moneyspent, msdt, n01, n02, n03, n05,
## n06, n07, n08, n1, n10, n100, n101, n102, n103, n11, n12, n13,
## n14, n15, n16, n1b, n2, n3, n35, n36, n37, n38, n39,
## n3posterb, n4, n40, n41, n42, n43, n44, n45, n46, n47, n48,
## n49, n5, n50, n51, n52, n53, n54, n55, n56, n57, n58, n59, n6,
## n60, n61, n61a, n62, n62a, n63, n63a, n64, n64a, n65, n65a,
## n66, n66a, n67, n67a, n68, n68a, n7, n77, n78, n7tren, n8,
## n88, n89, n8nha, n9, n97, n98, n99, n9khach, noE, noEnvi2,
## occup1, poli4, poli4a, policy, policy_a, policyeffect,
## reasons, reasons1, s1, Screening, selfhealth, SH1, smostt,
## taxIn, ter_fa1, ter_in, tertile_fa, tertile_indi, test,
## unitsdiffi1, var242, w1, w2, w3, w4
newdata2$age_group2[newdata2$age_group=="group18-29"] <- 1
newdata2$age_group2[newdata2$age_group=="gr3039"] <- 1
newdata2$age_group2[newdata2$age_group=="gr4049"] <- 0
newdata2$age_group2[newdata2$age_group=="gr5059"] <- 0
newdata2$age_group2[newdata2$age_group=="60plus"] <- 0
newdata2$age_group2=as.factor(newdata2$age_group2)
newdata2$educ2=as.factor(newdata2$educ2)
newdata2$h1=as.factor(newdata2$h1)
newdata2$d1a=as.factor(newdata2$d1a)
newdata2$b6b=as.factor(newdata2$b6b)
newdata2$selfhealth=as.factor(newdata2$selfhealth)
newdata2$b18a=as.factor(newdata2$b18a)
newdata2$b16a=as.factor(newdata2$b16a)
newdata2$smostt=as.factor(newdata2$smostt)
newdata2$ter_in=as.factor(newdata2$ter_in)
newdata2$group_age1=as.factor(newdata2$group_age1)
newdata2$label1=as.factor(newdata2$label1)
newdata2$freeEn=as.factor(newdata2$freeEn)
newdata2$c7ad=as.factor(newdata2$c7ad)
newdata2$ant=as.factor(newdata2$ant)
newdata2$p=as.factor(newdata2$p)
newdata2$in00[newdata2$ter_in==1] <- 1
newdata2$in00[newdata2$ter_in==2 | ter_in==3] <- 0
newdata2$in00=as.factor(newdata2$in00)
attach(newdata2)
## The following objects are masked from newdata2 (pos = 3):
##
## a, a1, advice, ag, age_group, ant, anticam, b1, b10, b10a1,
## b10a2, b10a3, b10a4, b10a5, b10a6, b10a7, b11, b11a, b11a2,
## b11a3, b12, b12a, b13, b14, b15, b16, b16a, b17, b18, b18a,
## b1a, b1a1, b1a2, b1a3, b2, b2a1, b3, b4, b5, b5a, b6, b6_123,
## b6a, b6a1, b6a2, b6a3, b6a4, b6a5, b6a6, b6a7, b6a7a, b6b, b7,
## b8, b9, br, branch, branch1, branch2, branch3, c1, c2, c23a,
## c3, c4, c5, c6, c6a111, c7, c7ad, c8, c9, clog, clog1, COST,
## cost_inc, cost1, costincrease, ct, d1, d10, d11, d1a, d2, d3,
## d3a, d4, d5, d6, d7, d8, d9, Decision, e1, e2, edu, educ1,
## educ2, f1, freeEn, ghi1, ghi2, ghiro2, giadinhkoUH, group_age,
## group_age1, h1, h10a, h10a1, h10a10, h10a11, h10a11a, h10a2,
## h10a3, h10a4, h10a5, h10a6, h10a7, h10a8, h10a9, h12, h12a,
## h12a_1, h12log, h13, h2, h3, h4, h5, h6, h7, h8, h9, ha000,
## highper, ict1a, ict2a, itc1, itc2, l1, l2, l3, l4, l5, l6,
## label_1, label1, label1a, logb7, logC, logC1, logC2,
## logitCost, moneyspent, msdt, n01, n02, n03, n05, n06, n07,
## n08, n1, n10, n100, n101, n102, n103, n11, n12, n13, n14, n15,
## n16, n1b, n2, n3, n35, n36, n37, n38, n39, n3posterb, n4, n40,
## n41, n42, n43, n44, n45, n46, n47, n48, n49, n5, n50, n51,
## n52, n53, n54, n55, n56, n57, n58, n59, n6, n60, n61, n61a,
## n62, n62a, n63, n63a, n64, n64a, n65, n65a, n66, n66a, n67,
## n67a, n68, n68a, n7, n77, n78, n7tren, n8, n88, n89, n8nha,
## n9, n97, n98, n99, n9khach, noE, noEnvi2, occup1, p, p1,
## poli4, poli4a, policy, policy_a, policyeffect, reasons,
## reasons1, s1, Screening, selfhealth, SH1, smostt, taxIn,
## ter_fa1, ter_in, tertile_fa, tertile_indi, test, unitsdiffi1,
## var242, w1, w2, w3, w4, wtp
## The following objects are masked from r1:
##
## a, a1, advice, ag, age_group, anticam, b1, b10, b10a1, b10a2,
## b10a3, b10a4, b10a5, b10a6, b10a7, b11, b11a, b11a2, b11a3,
## b12, b12a, b13, b14, b15, b16, b16a, b17, b18, b18a, b1a,
## b1a1, b1a2, b1a3, b2, b2a1, b3, b4, b5, b5a, b6, b6_123, b6a,
## b6a1, b6a2, b6a3, b6a4, b6a5, b6a6, b6a7, b6a7a, b6b, b7, b8,
## b9, br, branch, branch1, branch2, branch3, c1, c2, c23a, c3,
## c4, c5, c6, c6a111, c7, c8, c9, clog, clog1, COST, cost_inc,
## cost1, costincrease, ct, d1, d10, d11, d1a, d2, d3, d3a, d4,
## d5, d6, d7, d8, d9, Decision, e1, e2, edu, educ1, educ2, f1,
## ghi1, ghi2, ghiro2, giadinhkoUH, group_age, group_age1, h1,
## h10a, h10a1, h10a10, h10a11, h10a11a, h10a2, h10a3, h10a4,
## h10a5, h10a6, h10a7, h10a8, h10a9, h12, h12a, h12a_1, h12log,
## h13, h2, h3, h4, h5, h6, h7, h8, h9, ha000, ict1a, ict2a,
## itc1, itc2, l1, l2, l3, l4, l5, l6, label_1, label1, label1a,
## logb7, logC, logitCost, moneyspent, msdt, n01, n02, n03, n05,
## n06, n07, n08, n1, n10, n100, n101, n102, n103, n11, n12, n13,
## n14, n15, n16, n1b, n2, n3, n35, n36, n37, n38, n39,
## n3posterb, n4, n40, n41, n42, n43, n44, n45, n46, n47, n48,
## n49, n5, n50, n51, n52, n53, n54, n55, n56, n57, n58, n59, n6,
## n60, n61, n61a, n62, n62a, n63, n63a, n64, n64a, n65, n65a,
## n66, n66a, n67, n67a, n68, n68a, n7, n77, n78, n7tren, n8,
## n88, n89, n8nha, n9, n97, n98, n99, n9khach, noE, noEnvi2,
## occup1, poli4, poli4a, policy, policy_a, policyeffect,
## reasons, reasons1, s1, Screening, selfhealth, SH1, smostt,
## taxIn, ter_fa1, ter_in, tertile_fa, tertile_indi, test,
## unitsdiffi1, var242, w1, w2, w3, w4
# Tao newdataset: new dataset will work for futher analyst
data=subset(newdata2, select=c(logC1,age_group2, d1a,ter_in, educ2, selfhealth, c1, smostt, b6b, h1, b18a,b6a,label1,freeEn,ant, c7ad, p))
attach(data)
## The following objects are masked from newdata2 (pos = 3):
##
## age_group2, ant, b18a, b6a, b6b, c1, c7ad, d1a, educ2, freeEn,
## h1, label1, logC1, p, selfhealth, smostt, ter_in
## The following objects are masked from newdata2 (pos = 4):
##
## ant, b18a, b6a, b6b, c1, c7ad, d1a, educ2, freeEn, h1, label1,
## logC1, p, selfhealth, smostt, ter_in
## The following objects are masked from r1:
##
## b18a, b6a, b6b, c1, d1a, educ2, h1, label1, selfhealth,
## smostt, ter_in
#Tabe 1
require(moonBook)
## Loading required package: moonBook
## Warning: package 'moonBook' was built under R version 3.3.3
mytable(age_group2~.,data=data)
##
## Descriptive Statistics by 'age_group2'
## __________________________________________
## 0 1 p
## (N=194) (N=267)
## ------------------------------------------
## logC1 4.8 ± 0.3 4.9 ± 0.2 0.001
## d1a 0.000
## - none 14 ( 7.2%) 166 (62.2%)
## - married 180 (92.8%) 101 (37.8%)
## ter_in 0.524
## - 1 85 (44.5%) 106 (40.5%)
## - 2 46 (24.1%) 75 (28.6%)
## - 3 60 (31.4%) 81 (30.9%)
## educ2 0.000
## - 1 74 (38.9%) 22 ( 8.4%)
## - 2 98 (51.6%) 122 (46.6%)
## - 3 18 ( 9.5%) 118 (45.0%)
## selfhealth 0.000
## - notwell 130 (67.0%) 124 (46.4%)
## - good 64 (33.0%) 143 (53.6%)
## c1 0.001
## - 1 180 (92.8%) 218 (81.6%)
## - 2 14 ( 7.2%) 49 (18.4%)
## smostt 0.000
## - light 36 (18.6%) 91 (34.1%)
## - medium 68 (35.1%) 105 (39.3%)
## - heavy 90 (46.4%) 71 (26.6%)
## b6b 0.043
## - 0 138 (71.5%) 161 (61.9%)
## - 1 55 (28.5%) 99 (38.1%)
## h1 0.508
## - 0 75 (38.7%) 94 (35.2%)
## - 1 119 (61.3%) 173 (64.8%)
## b18a 0.780
## - Good 63 (32.6%) 91 (34.3%)
## - bad 130 (67.4%) 174 (65.7%)
## b6a 0.080
## - no 168 (87.0%) 209 (80.4%)
## - yes 25 (13.0%) 51 (19.6%)
## label1 0.022
## - 0 152 (78.4%) 231 (86.8%)
## - 1 42 (21.6%) 35 (13.2%)
## freeEn 0.124
## - 0 153 (79.3%) 193 (72.6%)
## - 1 40 (20.7%) 73 (27.4%)
## ant 0.122
## - 0 94 (48.5%) 150 (56.2%)
## - 1 100 (51.5%) 117 (43.8%)
## c7ad 0.498
## - 0 131 (67.5%) 171 (64.0%)
## - 1 63 (32.5%) 96 (36.0%)
## p 0.779
## - 0 53 (27.5%) 81 (30.5%)
## - 1 63 (32.6%) 82 (30.8%)
## - 2 77 (39.9%) 103 (38.7%)
## ------------------------------------------
```