jalan-jalan sambil minum teh-tarek

Thursday, August 25, 2016

code utk plot prediksi grip

insheet using S1t5histLG.txt, clear
capture label drop _all
label def clusterl 1 "Non-poor" 2 Poor
label val cluster clusterl
gen gripFhat = 28.1458 - (cluster-1)*1.1932 -  ///
  age*0.3028 - asset2*0.5004 - asset3*0.4361 + ///
  asset4*0.0741 - asset5*0.1701 + hischool*2.2141 + ///
  somecoll*5.5721 + intermed*1.7347 + managerial*3.7451 + ///
  mmarried*1.9781 + msepdiv*4.79041 + mwidowed*2.0289 + ///
  height*0.0926 - zonesouth*2.71820 - adillness*0.3663 - ///
  occelnum35*0.3856collapse gripFhat, by(age cluster)
label var gripFhat "Predicted grip strength"
twoway (lfitci gripFhat age if cluster==1) ///
  (lfitci gripFhat age if cluster==2, lpattern(dash) color(orange) ), ///
  legend(region(lwidth(none)) row(1) label (1 "Non-poor") label (2 " ") ///
          label (3 "Poor") label (4 " ")) scheme(s1color) saving(gripfemale.gph, replace)
gr combine gripmale.gph gripfemale.gph, row(1) iscale(1)
graph export grip.eps
graph export grip.png
graph export grip.pdf

code utk plot koefisien

clear
input str15 modnm str20 varnm coef se
"Male"    "Poor childhood"    -2.1917    0.2189
"Male"    "Age"    -0.4184    0.0112
"Male"    "Height"    0.1303    0.0188
"Male"    "Southern Europe"    -2.5454    0.2862
"Male"    "Adult illness"    -0.6170    0.1445
"Male"    "Adult elementary occ"    -0.7460    0.0801
"Female"    "Poor childhood"    -1.1932    0.2370
"Female"    "Age"    -0.3028    0.0100
"Female"    "Height"    0.0926    0.0212
"Female"    "Southern Europe"    -2.7182    0.2662
"Female"    "Adult illness"    -0.3664    0.0780
"Female"    "Adult elementary occ"    -0.3857    0.0934
end
gen min95 = coef - 1.96*se
gen max95 = coef + 1.96*se
sencode modnm, gen(modtype)
sencode varnm, gen(predictor)
levelsof predictor, local(ylabs)
label var modtype "Model"
label var predictor "Predictor"
sort modtype predictor
eclplot coef min95 max95 predictor, horiz ///
   estopts(msymbol(circle) msize(small)) ///
   by(modtype, legend(off) r(1)compact  note(" ")  ) /// blank note avoids unnecessary legend
   xline(0, lpattern(shortdash)) ylab(`ylabs') xtitle("")
graph export gripcoeff.pdf, replace
graph export gripcoeff.png, replace
graph export gripcoeff.eps, replace