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...
Fixed effects panel data regressionHi all, I am trying to run a panel data regression, between firm performance and some firm-specific…
Re: Testing median for baseline and endline dataGreetings Stata Users, I am working on baseline and endline surveys data collected using complex su…
How to make more than seven categories of a categorical variable transformed from a continuous variable through menu and dialogue box?Can we develop more than seven categories of a categorical variable transformed from a continuous va…
How can we save reordered variables as it always returns to previous order even when I save it?How can we save reordered variables as it always returns to previous order even when I save it? …
Create and export spatial matrix: spmatrix does not find the matrix created in MataI have a code that partially works to create a spatial matrix: egen id = group(IOCode),label lname(…
Subscribe to:
Post Comments (Atom)
0 Response to loop for if for making graphs...
Post a Comment