/* Code to run examples */ /* Mou, Liu, and Xu 2023 */ clear set more off cap log close * please set path global root= "Stata_Figures" ****************** /* installation */ ****************** *Uninstall // cap ado uninstall panelview //in-case already installed *Dependent packages* // net install grc1leg, from(http://www.stata.com/users/vwiggins) replace // net install gr0075, from(http://www.stata-journal.com/software/sj18-4) replace // ssc install labutil, replace // ssc install sencode, replace // ssc install panelview, all replace /* install from web */ // net install panelview, all replace from("https://yiqingxu.org/packages/panelview_stata") ****************************************************** /* Plotting treatment conditions and missing values */ ****************************************************** sysuse turnout, clear * Figure 1(a) panelview turnout policy_edr policy_mail_in policy_motor, /// i(abb) t(year) type(treat) xtitle("Year") ytitle("State") /// title("Treatment Status") graph export "$root/Figure1a.png", replace * Figure 1(b) panelview turnout policy_edr policy_mail_in policy_motor, /// i(abb) t(year) type(treat) xtitle("Year") ytitle("State") /// title("Treatment Status") /// bytiming legend(label(1 "No EDR") label(2 "EDR")) graph export "$root/Figure1b.png", replace * Figure 1(c) panelview turnout policy_edr policy_mail_in policy_motor, /// i(abb) t(year) type(treat) xtitle("Year") ytitle("State") /// title("Treatment Status") prepost graph export "$root/Figure1c.png", replace panelview policy_edr, /// i(abb) t(year) type(treat) xtitle("Year") ytitle("State") /// title("EDR Reform") prepost ylabel(none) * Figure 2 (with time gaps) drop if year==1924 | year==1928 | year==1940 panelview turnout policy_edr policy_mail_in policy_motor, /// i(abb) t(year) type(treat) leavegap graph export "$root/Figure2.png", replace * Treatment switching on and off * * Figure 3 sysuse capacity.dta, clear egen ccodeid = group(ccode) panelview Capacity demo lnpop lngdp ccodeid if ccodeid >= 1 & ccodeid <= 100, /// i(ccode) t(year) type(treat) ylabel(none) /// title("Democracy and State Capacity") xlabdist(3) graph export "$root/Figure3.png", replace * High dimensional data (sorted by treatment timing) * Figure 4(a) sysuse capacity.dta, clear panelview Capacity demo lnpop lngdp, i(ccode) t(year) type(treat) /// xlabdist(3) collapsehistory title("Unique Treatment Histories") graph export "$root/Figure4a.png", replace * Figure 4(b) sysuse turnout, clear panelview turnout policy_edr policy_mail_in policy_motor, i(abb) t(year) /// type(treat) collapsehistory title("Unique Treatment Histories") graph export "$root/Figure4b.png", replace * More than two treatment conditions * * Figure 5(a) sysuse capacity.dta, clear gen demo2 = 0 replace demo2 = -1 if polity2 < -0.5 replace demo2 = 1 if polity2 > 0.5 panelview Capacity demo2 lngdp, i(ccode) t(year) /// type(treat) title("Regime Type") xlabdist(3) ylabdist(10) graph export "$root/Figure5a.png", replace * Figure 5(b) panelview Capacity polity2 lngdp, i(ccode) t(year) type(treat) /// title("Regime Type") xlabdist(3) ylabdist(10) graph export "$root/Figure5b.png", replace * Showing missing values only * Figure 6 panelview Capacity, i(ccode) t(year) type(missing) /// title("Missing Values") xlabel(none) ylabel(none) graph export "$root/Figure6.png", replace * Show aggregate treatment adoption and outcome trend sysuse turnout, clear panelview turnout policy_edr, i(abb) t(year) xlabdist(7) /// type(bivariate) msize(*0.5) style(c b) ytitle("turnout") /// ytitle("policy_edr", axis(2)) legend(label(1 "turnout") /// label(2 "policy_edr")) ylabel(40 (10) 70) /// ylabel(0 (0.1) 0.5, axis(2)) ************************************************************ /* Plotting the temporal dynamics of an outcome variable */ ************************************************************ * Continuous outcome * sysuse turnout.dta, clear * Figure 7(a) panelview turnout policy_edr policy_mail_in policy_motor, /// i(abb) t(year) type(outcome) xtitle("Year") ytitle("Turnout") /// title("EDR Reform and Turnout") prepost graphregion(fcolor(white)) graph export "$root/Figure7a.png", replace * Figure 7(b) panelview turnout policy_edr policy_mail_in policy_motor, /// i(abb) t(year) type(outcome) xtitle("Year") ytitle("Turnout") /// bygroup xlabel(1920 (20) 2000) graph export "$root/Figure7b.png", replace * Figure 8(a) panelview turnout policy_edr policy_mail_in policy_motor /// if abb == 1|abb == 2|abb == 6, /// i(abb) t(year) type(outcome) xtitle("Year") ytitle("Turnout") /// title("EDR Reform and Turnout (AL, AR, CT)") prepost graph export "$root/Figure8a.png", replace * Figure 8(b) panelview turnout, i(abb) t(year) type(outcome) ignoretreat /// title("Turnout") ylabel(0 (25) 100) graph export "$root/Figure8b.png", replace * Discrete outcome * sysuse simdata.dta, clear * Figure 9(a) panelview Y D if time >= 8 & time <= 15, /// type(outcome) i(id) t(time) discreteoutcome /// title("Raw Data") xlabel(8 (2) 15) ylabel(0 (1) 2) graph export "$root/Figure9a.png", replace * Figure 9(b) panelview Y D if time >= 8 & time <= 15, /// type(outcome) i(id) t(time) discreteoutcome by(,title("Raw Data")) /// xlabel(8 (2) 15) ylabel(0 (1) 2) bygroup prepost graph export "$root/Figure9b.png", replace ***************************************** /* Visualizing bivariate relationships */ ***************************************** * Plotting bivariate relationships in aggreage * * Figure 10(a) sysuse turnout.dta, clear panelview turnout policy_edr, i(abb) t(year) xlabdist(7) type(bivariate) /// msize(*0.5) style(c b) ytitle("turnout") /// ytitle("policy_edr", axis(2)) /// legend(label(1 "turnout") label(2 "policy_edr")) /// ylabel(45 (5) 65) ylabel(0 (0.05) 0.2, axis(2)) graph export "$root/Figure10a.png", replace * Figure 10(b) sysuse capacity.dta, clear panelview Capacity polity2, i(country) t(year) type(bivar) xlabdist(20) graph export "$root/Figure10b.png", replace * Plotting bivariate relationship by each unit * * Figure 11(a) sysuse turnout.dta, clear panelview turnout policy_edr policy_mail_in policy_motor /// if abb >= 10 & abb <= 21, /// i(abb) t(year) xlabdist(10) type(bivar) byunit graph export "$root/Figure11a.png", replace * Figure 11(b) sysuse capacity.dta, clear panelview Capacity polity2 /// if country >= 20 & country <= 25 | country >= 40 & country <= 45, /// i(country) t(year) xlabdist(20) /// type(bivar) byunit graph export "$root/Figure11b.png", replace