I run the command below to a lowess curve for two of the indenpendent variables on the same graph, however, Stata only generates two separate graphs for me. I use Stata SE/17.
logit voted ldmission ldcatho i.gender age age2 education i.urbrur living_cond i.catholic_now i.protestant_now i.muslim_now religiosity lslave_region slave_region ldcity1800 lpopd_history ldcoast ldrail ldexplorer dexplorer_0 ldprint ldhospital ldbig30 i.Country i.Wave
predict voted_pred_mission, p
global y_all "voted_pred_mission"
foreach y of varlist voted_pred_mission{
cap noisily drop lowess*
local x: variable label `y'
lowess `y' ldcatho if ldcatho<5.2, nograph gen(lowess_`y') bwidth(0.5) adjust
gr twoway line lowess_`y' ldcatho if ldcatho<5.2 ///
, sort(ldcatho) color(blue) ///
cap noisily drop lowess*
local x: variable label `y'
lowess `y' ldmission if ldmission<5.2, nograph gen(lowess_`y') bwidth(0.5) adjust
gr twoway line lowess_`y' ldmission if ldmission<5.2 ///
, sort(ldmission) color(blue) ///
xtitle("Distance to Mission") ytitle("Probability of Voting") ///
graphregion(color(white))
gr export "bymissionvote.pdf", replace
}
logit voted ldmission ldcatho i.gender age age2 education i.urbrur living_cond i.catholic_now i.protestant_now i.muslim_now religiosity lslave_region slave_region ldcity1800 lpopd_history ldcoast ldrail ldexplorer dexplorer_0 ldprint ldhospital ldbig30 i.Country i.Wave
predict voted_pred_mission, p
global y_all "voted_pred_mission"
foreach y of varlist voted_pred_mission{
cap noisily drop lowess*
local x: variable label `y'
lowess `y' ldcatho if ldcatho<5.2, nograph gen(lowess_`y') bwidth(0.5) adjust
gr twoway line lowess_`y' ldcatho if ldcatho<5.2 ///
, sort(ldcatho) color(blue) ///
cap noisily drop lowess*
local x: variable label `y'
lowess `y' ldmission if ldmission<5.2, nograph gen(lowess_`y') bwidth(0.5) adjust
gr twoway line lowess_`y' ldmission if ldmission<5.2 ///
, sort(ldmission) color(blue) ///
xtitle("Distance to Mission") ytitle("Probability of Voting") ///
graphregion(color(white))
gr export "bymissionvote.pdf", replace
}
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte gender float(age age2 education) byte(urbrur living_cond) float(catholic_now protestant_now muslim_now) long(Country Wave) 1 38 1444 2 2 3 0 0 0 15 1 2 44 1936 2 2 4 0 1 0 15 1 2 32 1024 4 2 2 0 1 0 15 1 1 35 1225 3 2 1 0 0 0 15 1 1 29 841 6 2 4 0 1 0 15 1 2 18 324 4 2 3 0 0 0 15 1 2 56 3136 5 2 4 1 0 0 15 1 1 35 1225 6 2 3 0 1 0 15 1 2 41 1681 3 2 4 0 1 0 15 2 1 63 3969 3 2 4 0 0 0 15 1 2 36 1296 4 2 2 0 0 0 15 1 1 46 2116 4 1 4 0 1 0 15 2 2 40 1600 3 2 2 0 0 0 15 2 2 63 3969 2 2 2 0 0 0 15 1 1 71 5041 0 2 4 0 0 0 15 1 2 36 1296 2 2 3 0 0 0 15 2 1 34 1156 4 2 4 0 0 0 15 1 1 36 1296 3 2 1 0 0 0 15 1 2 67 4489 4 2 2 0 1 0 15 1 2 21 441 4 1 3 0 1 0 15 1 2 40 1600 2 2 3 1 0 0 15 1 1 24 576 2 2 3 0 0 0 15 1 2 21 441 4 2 3 0 0 0 15 1 2 18 324 4 2 4 0 1 0 15 2 2 27 729 4 2 4 0 1 0 15 2 2 64 4096 2 2 3 0 1 0 15 1 1 23 529 4 2 5 0 0 0 15 1 2 41 1681 4 2 1 0 1 0 15 2 2 28 784 5 1 4 0 1 0 15 2 1 45 2025 2 1 5 0 1 0 15 2 2 40 1600 3 1 1 0 1 0 15 2 2 69 4761 3 2 3 0 1 0 15 2 2 46 2116 6 2 3 0 1 0 15 1 2 54 2916 3 2 2 0 1 0 15 2 1 53 2809 0 2 3 1 0 0 15 1 2 67 4489 2 2 3 1 0 0 15 1 1 43 1849 5 2 2 0 1 0 15 1 1 19 361 4 2 3 0 0 0 15 1 1 25 625 5 2 3 0 1 0 15 1 1 73 5329 3 2 4 0 1 0 15 1 2 20 400 5 2 3 0 1 0 15 1 1 67 4489 4 2 3 0 0 0 15 1 2 67 4489 5 1 3 0 1 0 15 2 2 18 324 5 2 3 0 0 0 15 1 1 19 361 3 2 2 0 0 0 15 1 1 58 3364 6 1 4 0 1 0 15 2 1 41 1681 2 1 4 1 0 0 15 1 2 59 3481 3 2 3 0 0 0 15 1 1 20 400 4 2 4 0 1 0 15 2 2 19 361 4 2 4 0 0 0 15 1 2 56 3136 3 2 4 0 0 0 15 1 2 46 2116 5 2 3 0 1 0 15 1 1 55 3025 2 2 3 1 0 0 15 1 2 64 4096 2 2 3 0 1 0 15 1 2 63 3969 0 2 3 0 0 0 15 2 1 36 1296 5 1 2 0 1 0 15 1 1 67 4489 4 2 2 0 1 0 15 1 1 45 2025 5 1 4 0 1 0 15 2 2 60 3600 4 2 3 0 1 0 15 1 1 22 484 4 2 3 0 1 0 15 1 2 20 400 5 2 3 0 0 0 15 1 1 28 784 3 2 3 0 0 0 15 2 1 80 6400 0 2 4 0 0 0 15 2 1 43 1849 9 1 3 0 1 0 15 1 2 88 7744 6 2 4 1 0 0 15 1 1 68 4624 2 2 2 0 1 0 15 2 1 53 2809 3 2 4 0 0 0 15 2 1 51 2601 2 1 4 0 0 0 15 2 2 50 2500 2 2 2 0 1 0 15 2 1 66 4356 0 2 3 0 1 0 15 1 1 60 3600 3 2 4 0 1 0 15 2 2 58 3364 4 1 4 0 1 0 15 2 1 51 2601 2 2 3 0 1 0 15 2 2 58 3364 2 1 3 0 1 0 15 2 1 49 2401 4 2 4 0 1 0 15 2 1 60 3600 2 2 4 1 0 0 15 1 2 38 1444 4 2 3 0 0 0 15 1 2 25 625 4 2 3 0 1 0 15 1 1 40 1600 4 1 4 0 1 0 15 1 1 20 400 4 2 4 0 0 0 15 1 1 43 1849 2 2 3 0 0 0 15 1 1 35 1225 4 2 3 0 1 0 15 1 2 53 2809 2 1 2 0 1 0 15 2 1 23 529 4 2 3 0 0 0 15 2 2 66 4356 0 2 4 0 0 0 15 1 1 22 484 4 2 4 0 1 0 15 2 1 19 361 4 1 3 1 0 0 15 2 1 37 1369 6 2 4 1 0 0 18 1 1 35 1225 5 2 3 0 0 0 18 1 2 27 729 2 1 2 0 1 0 18 1 1 37 1369 8 1 2 0 0 0 18 1 2 25 625 5 1 3 0 1 0 18 1 2 47 2209 3 1 3 0 0 0 18 2 2 35 1225 6 1 2 0 1 0 18 1 1 33 1089 3 2 4 0 1 0 16 2 2 19 361 4 1 3 0 0 0 18 1 2 33 1089 0 2 4 0 1 0 18 2 1 36 1296 3 2 3 1 0 0 16 2 1 49 2401 3 1 1 0 0 1 16 2 1 25 625 3 2 4 0 0 0 16 1 end label values gender LABAR label def LABAR 1 "male", modify label def LABAR 2 "female", modify label values urbrur urbrur label def urbrur 1 "urban", modify label def urbrur 2 "rural", modify label values living_cond LABI label def LABI 1 "much worse", modify label def LABI 2 "worse", modify label def LABI 3 "same", modify label def LABI 4 "better", modify label def LABI 5 "much better", modify label values Country country label def country 15 "SOUTH AFRICA", modify label def country 16 "TANZANIA", modify label def country 18 "ZAMBIA", modify label values Wave wave label def wave 1 "round3", modify label def wave 2 "round4", modify
Comment