I have a 50 US state panel by day. A policy of interest is implemented in the different states at different calendar times. I want to create a raw trend graph, with faint 50 individual lines (one for each state) and a prominent national 7 past days moving-average. A colleague made a similar graph in R that I want to replicate in Stata. Array
The faint individual state lines are light gray before the policy (SAH=0) and turn red after (SAH=1). Here is an example of my data:
[CODE]
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str3 state float(date MixingIndex PostStayAtHome) "ID" 22014 31.463 1 "DE" 22014 49.0593 1 "CT" 22014 25.0929 0 "WI" 22014 30.1077 1 "OH" 22014 52.2867 1 "MA" 22014 22.7127 0 "IL" 22014 41.741 1 "MO" 22014 50.129 1 "AZ" 22014 46.6066 1 "ND" 22014 40.8167 0 "OR" 22014 26.9406 1 "AR" 22014 69.3435 0 "VA" 22014 54.8447 1 "CO" 22014 35.5311 1 "MI" 22014 34.5329 1 "AL" 22014 63.8846 1 "MT" 22014 59.583 1 "WY" 22014 31.9032 0 "RI" 22014 22.0092 1 "GA" 22014 68.6803 1 "OK" 22014 72.9961 1 "MS" 22014 66.8261 1 "NV" 22014 49.6798 1 "VT" 22014 8.0608 1 "MD" 22014 57.1494 1 "PA" 22014 38.686 1 "ME" 22014 13.3021 1 "UT" 22014 49.8481 1 "NC" 22014 61.8271 1 "NM" 22014 35.7423 0 "KY" 22014 58.3239 0 "TN" 22014 66.5646 1 "NE" 22014 42.0665 0 "SD" 22014 32.93 0 "MN" 22014 34.6475 1 "KS" 22014 40.1936 1 "WA" 22014 29.5035 1 "IN" 22014 48.0393 1 "FL" 22014 86.0191 1 "LA" 22014 60.8262 1 "NH" 22014 24.3938 1 "NY" 22014 30.2026 1 "WV" 22014 39.7102 1 "CA" 22014 21.4493 1 "IA" 22014 40.9553 0 "SC" 22014 61.2586 1 "NJ" 22014 35.1612 1 "TX" 22014 88.6879 1 "KY" 22015 81.1891 0 "AZ" 22015 64.0656 1 "NM" 22015 47.5383 0 "IL" 22015 61.5071 1 "CA" 22015 29.3606 1 "NE" 22015 63.6709 0 "ND" 22015 60.4925 0 "IN" 22015 69.8765 1 "NC" 22015 91.286 1 "GA" 22015 102.5218 1 "DE" 22015 68.6849 1 "NJ" 22015 49.5785 1 "AL" 22015 98.9698 1 "MN" 22015 56.8027 1 "FL" 22015 117.9994 1 "TX" 22015 119.3716 1 "LA" 22015 74.6568 1 "OK" 22015 108.9088 1 "WV" 22015 55.4178 1 "OR" 22015 38.3399 1 "ID" 22015 45.6788 1 "CO" 22015 51.1373 1 "MO" 22015 75.0492 1 "RI" 22015 39.1012 1 "NY" 22015 41.6955 1 "CT" 22015 41.5765 0 "MT" 22015 83.5388 1 "NH" 22015 42.4985 1 "TN" 22015 92.0391 1 "SD" 22015 56.9478 0 "MD" 22015 78.1994 1 "VA" 22015 76.6454 1 "IA" 22015 66.932 0 "KS" 22015 58.9908 1 "AR" 22015 102.5041 0 "PA" 22015 56.576 1 "NV" 22015 65.4456 1 "WI" 22015 47.4254 1 "SC" 22015 92.7654 1 "WY" 22015 45.4421 0 "ME" 22015 22.7119 1 "MI" 22015 45.4081 1 "MA" 22015 37.9647 0 "MS" 22015 95.5885 1 "VT" 22015 12.5291 1 "OH" 22015 79.3861 1 "UT" 22015 66.0233 1 "WA" 22015 40.4813 1 "ID" 22016 74.3028 1 "GA" 22016 110.0505 1 "AL" 22016 106.7091 1 "AZ" 22016 113.8531 1 end
Code:
# delimit ; twoway (scatter MixingIndex date if PostStayAtHome==0 & MixingIndex<400, color(gs10) msize(tiny)) (line meanMixingIndex_mean date , lwidth(medthick) lcolor(black)) (scatter MixingIndex date if PostStayAtHome==1 & MixingIndex<400, color(ltblue) mcolor(%40) msize(tiny)) , xsize(2.5) ysize(2) xtitle("") ytitle("Mixing Index", size(small)) graphregion(color(white)) xlabel(, labsize(small) nogrid) ylabel(, labsize(small) nogrid) legend(off) graphregion(margin(r+5)) title("Mixing Index", pos(14) size(3.5)) name(Trend, replace) ;
Many thanks,
Sumedha.
0 Response to Multiple twoway lines in same graph region.
Post a Comment