Hi statalist,
I would like to make a graph using lowess command by treatment group.
I have 10 treatment groups: treat1, treat2,....,treat10
I tried
code:
twoway (lowess occupplace coh if treat1==1 & age>=25 & age<80 & occupplace<50) (lowess occupplace coh if treat1==0& age>=25& age<80 & occupplace<50), ytitle("Life time work place") xtitle("Birth Cohort (age)") legend (on order(1 "treat" 2 "control"))
graph export graph1.png
twoway (lowess occupplace coh if treat2==1 & age>=25 & age<80 & occupplace<50) (lowess occupplace coh if treat1==0& age>=25& age<80 & occupplace<50), ytitle("Life time work place") xtitle("Birth Cohort (age)") legend (on order(1 "treat" 2 "control"))
graph export graph2.png
twoway (lowess occupplace coh if treat3==1 & age>=25 & age<80 & occupplace<50) (lowess occupplace coh if treat1==0& age>=25& age<80 & occupplace<50), ytitle("Life time work place") xtitle("Birth Cohort (age)") legend (on order(1 "treat" 2 "control"))
graph export graph3.png
.
.
.
It works, but it is too long and I think there should be more clever way to do that.
Thus, I tried this
code:
local continuous treat1-treat10
foreach i of local continous {
twoway (lowess occupplace coh if `i'==1& age>=25 & age<80 & occupplace<50) (lowess occupplace coh if `i'==0& age>=25 & age<80 & occupplace<50) ,ytitle("Life time work place") xtitle("Birth Cohort (age)") legend (on order(1 "treat" 2 "control"))
graph export graph`i'.png
}
However it does not work...
Could you help me out?
Thank you in advance.
Related Posts with loop for if for making graphs...
error occurred while loading xtsur.ado Dear All, Greetings I use stata 14.1. I try to execute xtsur command . sometimes I get the result b…
Storing decile values correspong to decile rank in a separate variableHi everyone, I am writing to understand how I can store the decile values for the following dummy d…
Estimate Cohen´s (d) for within-subjects?Dear all, Which is the right formula for Cohen´s (d) for within-subjects? There are many formulas a…
Time-to-event analysis for panels STATA 13Hi all, I have the following database Code: * Example generated by -dataex-. To install: ssc inst…
How to find mean in a specific range.How can I find the mean value of “urban” variable from state “Alabama” to “Massachusetts”. What will…
Subscribe to:
Post Comments (Atom)
0 Response to loop for if for making graphs...
Post a Comment