Hello dear all,
I have panel data from about 140 countries. and I use the two-way chart.
and I want to exclude one country at a time and use different line colors.
But as it is so many countries, so, I do not know how to modify my code and allow the STATA to choose colors by default, not manually.
I do not know how to change the color line in a loop in a two-way command.
**here I just wrote the loop only based on about 30 countries.
I appreciate receiving your help.
Best,
I have panel data from about 140 countries. and I use the two-way chart.
and I want to exclude one country at a time and use different line colors.
But as it is so many countries, so, I do not know how to modify my code and allow the STATA to choose colors by default, not manually.
I do not know how to change the color line in a loop in a two-way command.
**here I just wrote the loop only based on about 30 countries.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str32 countryname float cur double ifscode float year double WUI_sum "United States" .5317895 111 1973 .0897666 "United States" .11001506 111 1974 .28516949999999996 "United States" 1.0611881 111 1975 .48200679999999996 "United States" .2049736 111 1976 .3596399 "United States" -.7253248 111 1977 1.0571842999999999 "United States" -.6696295 111 1978 .19876069999999998 "United States" -.005964223 111 1979 .5083416000000001 "United States" .074440725 111 1980 .24863100000000002 "United States" .1499825 111 1981 .3621824 "United States" -.3471212 111 1982 .3713493 "United States" -1.2168833 111 1983 .3962155 "United States" -2.452142 111 1984 .192419 "United States" -2.8683014 111 1985 .0839913 "United States" -3.213665 111 1986 .21242709999999998 "United States" -3.3087516 111 1987 .3327374 "United States" -2.315658 111 1988 .7352632 "United States" -1.7637967 111 1989 .36565369999999997 "United States" -1.3239995 111 1990 .39529499999999995 "United States" .04629653 111 1991 .1536587 "United States" -.7914488 111 1992 .2734836 "United States" -1.2361605 111 1993 .5693062999999999 "United States" -1.669253 111 1994 .2580359 "United States" -1.4864494 111 1995 .2924072 "United States" -1.5449674 111 1996 .1409335 "United States" -1.6406133 111 1997 .0495638 "United States" -2.3727388 111 1998 .4398425 "United States" -2.975982 111 1999 .2346321 "United States" -3.920886 111 2000 .2538247 "United States" -3.724075 111 2001 .9892922 "United States" -4.17334 111 2002 1.07912 "United States" -4.558981 111 2003 1.2123401 "United States" -5.204854 111 2004 .3570366 "United States" -5.745982 111 2005 .49987200000000004 "United States" -5.911019 111 2006 .23886079999999998 "United States" -5.088728 111 2007 1.094794 "United States" -4.7158613 111 2008 .6031295 "United States" -2.6228366 111 2009 1.0202793 "United States" -2.870643 111 2010 .8268708999999999 "United States" -2.918621 111 2011 .7264667 "United States" -2.572368 111 2012 1.5249123 "United States" -2.0153842 111 2013 .8904299 "United States" -2.108055 111 2014 .5881687 "United States" -2.243472 111 2015 1.073512 "United States" -2.1193724 111 2016 .8585571000000001 "United States" -1.8535286 111 2017 .7434678 "United States" -2.1421602 111 2018 .7691144999999999 "United States" -2.085756 111 2019 2.1541754 "United States" -2.9424884 111 2020 1.4796038999999999 "United States" -3.630071 111 2021 .38883500000000004 "United Kingdom" -1.2524583 112 1973 .0855359 "United Kingdom" -3.613082 112 1974 .38107559999999996 "United Kingdom" -1.433419 112 1975 .8089789 "United Kingdom" -.59336907 112 1976 1.0808285999999998 "United Kingdom" .05513242 112 1977 .3710501 "United Kingdom" .6441247 112 1978 1.0868924 "United Kingdom" -.17827246 112 1979 .9693126999999999 "United Kingdom" 1.2146102 112 1980 .46875239999999996 "United Kingdom" 2.612607 112 1981 .3194212 "United Kingdom" 1.5504085 112 1982 .36219169999999995 "United Kingdom" 1.08082 112 1983 .8144914 "United Kingdom" .3972896 112 1984 0 "United Kingdom" .67741 112 1985 .06320909999999999 "United Kingdom" -.22009194 112 1986 .2062234 "United Kingdom" -1.6895826 112 1987 0 "United Kingdom" -3.8812656 112 1988 .5320132 "United Kingdom" -4.650699 112 1989 .6230532 "United Kingdom" -3.550168 112 1990 1.230429 "United Kingdom" -1.6645445 112 1991 .6524292 "United Kingdom" -1.966937 112 1992 .3223508 "United Kingdom" -1.669506 112 1993 .3112551 "United Kingdom" -.8791173 112 1994 .08992339999999999 "United Kingdom" -.9980571 112 1995 .1008928 "United Kingdom" -.7264912 112 1996 .44899579999999995 "United Kingdom" -.08981485 112 1997 .7623446 "United Kingdom" -.31861085 112 1998 .6506400999999999 "United Kingdom" -2.1135337 112 1999 .5433545 "United Kingdom" -1.84713 112 2000 .2850048 "United Kingdom" -1.8055797 112 2001 .5955098 "United Kingdom" -2.0363908 112 2002 .27691750000000004 "United Kingdom" -1.884036 112 2003 .8814714 "United Kingdom" -2.362032 112 2004 .6360688 "United Kingdom" -2.0342944 112 2005 .6806401 "United Kingdom" -3.16443 112 2006 .5955746 "United Kingdom" -3.786051 112 2007 .8178505 "United Kingdom" -3.987796 112 2008 .7105001 "United Kingdom" -3.118611 112 2009 1.818801 "United Kingdom" -2.894801 112 2010 1.4819679000000001 "United Kingdom" -1.8039025 112 2011 1.3387272000000001 "United Kingdom" -3.2902634 112 2012 1.6197735999999998 "United Kingdom" -4.782701 112 2013 1.2138284000000001 "United Kingdom" -5.138112 112 2014 .9520833000000001 "United Kingdom" -5.066957 112 2015 1.9084387 "United Kingdom" -5.540469 112 2016 3.9415905 "United Kingdom" -3.610205 112 2017 1.8996527 "United Kingdom" -4.0648184 112 2018 2.433672 "United Kingdom" -2.827337 112 2019 4.7189962 "United Kingdom" -3.2468314 112 2020 3.4935945000000004 "United Kingdom" -1.5069276 112 2021 2.0885071 "" . 117 . . "" . 118 . . end
Code:
foreach v in "cur" { gen d`v'_0=f0.`v'- l.`v' gen d`v'_1=f1.`v'- l.`v' gen d`v'_2=f2.`v'- l.`v' gen d`v'_3=f3.`v'- l.`v' gen d`v'_4=f4.`v'- l.`v' gen d`v'_5=f5.`v'- l.`v' } foreach v in cur { foreach x in 111 112 122 124 128 132 134 136 138 142 144 146 156 158 172 174 178 182 184 186 193 196 199 213 218 223 { gen b`x'_`v' =0 } } foreach v in cur { gen b_`v' =0 gen se_`v'=0 gen up90_`v'=0 gen dn90_`v'=0 }
Code:
foreach x in 111 112 122 124 128 132 134 136 138 142 144 146 156 158 172 174 178 182 184 186 193 196 199 213 218 223 { foreach v in cur { forvalues i=0/4{ xtscc d`v'_`i' l(0/2)l.WUI_sum l(1/2)d`v'_0 i.year if dcur_0 !=. & l1.dcur_0 !=. & l2.dcur_0 !=. & dsav_0 !=. & l1.dsav_0 !=. & l2.dsav_0 !=. & dinv_0 !=. & l1.dinv_0 !=. & l2.dinv_0 !=. ,fe lincom l.WUI_sum, level(90) replace b_`v' = r(estimate)*SD_WUI_sum if _n == `i'+2 replace se_`v' = r(se) if _n == `i'+2 replace up90_`v' = (r(estimate) + 1.645*se_`v')*SD_WUI_sum if _n == `i'+2 replace dn90_`v' = (r(estimate) - 1.645*se_`v')*SD_WUI_sum if _n == `i'+2 xtscc d`v'_`i' l(0/2)l.WUI_sum l(1/2)d`v'_0 i.year if l1.dcur_0!=. & l1.dsav_0 !=. & l1.dinv_0!=. & d.inv!=. & d.sav!=. &d.cur!=. & ifscode!=`x',fe lincom l.WUI_sum, level(90) replace b`x'_`v' = r(estimate)*SD_WUI_sum if _n == `i'+2 } } }
Code:
foreach x in 111 112 122 124 128 132 134 136 138 142 144 146 156 158 172 174 178 182 184 186 193 196 199 213 218 223 { foreach v in cur { qui: twoway rarea dn90_`v' up90_`v' horizon if horizon <5, color(gs10) lpattern(dash) ylabel(-.4(0.2).6) xlabel(-1(1)4) || /// line b_`v' horizon if horizon <5, lcolor(blue) lpattern(solid) lwidth(medthick) xscale(range(-1 ) titleg(1)) || /// scatter b`x'_`v' horizon if horizon <5, c(l l l l l l l l l l) clp(tight_dot dash dash dash dash dash) ms(oh i i i i i i ) clc(red red red red red red) mc(red red red red red red) clw (medthick medthick medthick medthick medthick medthick) || /// line a horizon if horizon <5, mstyle(p1) lpattern(dash) lwidth(vthin) lcolor(gs0) /// title(, color(black) size(medium)) /// ytitle( " cur (% of GDP)", size(medsmall)) xtitle("Years after WUI", size(medsmall)) /// graphregion(color(white)) plotregion(color(white) ) /// , /// legend(order(2 "baseline" 3 "111" 4 "112" 5 "122" 6 "124" 7 "128" 8 "443" 9 "136" 10 "343" 11 "299" )) graph save `x'_mygraph, replace } }
I appreciate receiving your help.
Best,
Comment