凡是搞计量经济的,都关注这个号了
邮箱:econometrics666@126.com
所有计量经济圈方法论丛的code程序, 宏微观数据库和各种软件都放在社群里.欢迎到计量经济圈社群交流访问.
下面是一篇使用合成控制法SCM进行实证研究的文章的代码。对SCM方法感兴趣的学者,可以将其复制到Stata中对照着文章进行理解,以便将来开展自己的相关研究。针对各种方法的代码,公众号里已经有很多推荐了,有需要的学者可以自行检索【计量经济圈公众号搜索功能及操作流程演示】。
合成控制法SCM1.合成控制法创始人如何用SCM做实证呢?这些规定动作一个都不能少!2.关于合成控制法SCM的33篇精选Articles专辑!小组惊动了阿里巴巴!3.再谈合成控制法SCM, 帮你寻找因果推断控制组,4.最新: 运用机器学习和合成控制法研究武汉封城对空气污染和健康的影响!5.合成控制法与HCW方法, 谁能够走得更远?6.广义合成控制法gsynth, Stata运行程序release,7.广义合成控制法gsynth, 基于交互固定效应的因果推断,8.DID, 合成控制, 匹配, RDD四种方法比较, 适用范围和特征,9.合成控制法什么鬼? 因果推断的前沿方法指南,10.用回归控制法HCW(附程序和数据)评估各国经济刺激计划的影响, 真是一个好主意!11.计量院士为你讲解回归控制法HCW的操作, 并配上自己写的一篇范文!12.HCW面板数据政策评估方法, panel数据构造对照组,13.断点回归RD和合成控制法SCM免费课程, 文章, 数据和代码全在这里, 有必要认真研究学习!14.中文刊上用断点回归RDD和合成控制法SCM的实证文章有哪些?不看至少需要收藏一下!15.用合成控制法, 机器学习和面板数据模型开展政策评估的论文!*社群也上传的有,群友可以自行下载。
**下面的代码复制一篇文章“Carl Bonander,2017,Compared ith what? Estimating the effectsof injury prevention policies using the synthetic control method,Injury Prevention”____________________________________________________________
______________________________________________________________________*Change ... to the directory where you unzipped your data file.use rep_opioids.dta, clear*Define the incidence rate variable (per 100.000 population)gen rate = deaths/population*100000**Identify and drop states with missing outcome values (Synth doesn't likegen missing = missing(rate)by statecode (missing), sort: drop if missing[_N]==1*Tell Stata that the data is a panel dataset__________________________________________________________________________________________________________________________________________________The code works as follows:synth outcomevar covariate(s), optionswhere outcomevar is the outcome variable (rate in this case) and covariate(s) is a list of variables to match on. We can specify options for each variableusing () to modify the period matched on (see help file for further details).The options trunit(), trperiod() specifiy the treated state (id for Florida=12)and the start of the intervention period (2010).keep() tells synth to store the results in a separate file, which is usefulfor e.g. plotting in external programs, since it stores the outcomes in thesynthetic control unit. We will also exploit this feature later on to produceinferential statistics using permutation tests.unitnames() makes the output easier to interpet by displaying state names,as stored in the variable state, instead of id numbers._________________________________________________________________________Section 1: Model selection.Run a set of different matching specifications to select the best model_________________________________________________________________________We begin by selecting the best fitting matching specifiation,using the models suggested by Ferman et al. (2016, referenced in the paper).The results are stored in separate files (see the keep() option), whichcan be used for plotting them together.We can use this test for model selection by choosing the model that minimizesthe pre-intervention RMSPE (which is what Synth reports in the output), and presentthis model as the main result (as is done in the paper). We can also plot thestored results to identify if the results holds (approximately) for all or anyalternative specification (which lends more confidence in the results).As discussed in the paper, we choose the best fitting model of the optionsthat do not include the full vector of pre-intervention outcome years, sinceother covariates are included in the model (see notes below).*All years (note that covariate weights are set to zero in models with all outcome year)[1]synth rate rate(1999) rate(2000) rate(2001) rate(2002) rate(2003) rate(2004) rate(2005) rate(2006)rate(2007) rate(2008) rate(2009) gdp inc unemp_rate, ///trunit(12) trperiod(2010) fig keep(spec_1.dta, replace) unitnames(state)synth rate rate(1999) rate(2001) rate(2003) rate(2005) rate(2007) rate(2009) gdp inc unemp_rate, ///trunit(12) trperiod(2010) fig keep(spec_2.dta, replace) unitnames(state)synth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, ///trunit(12) trperiod(2010) fig keep(spec_3.dta, replace) unitnames(state)synth rate rate gdp inc unemp_rate, ///trunit(12) trperiod(2010) fig keep(spec_4.dta, replace) unitnames(state)synth rate rate(1999) rate(2001) rate(2002) rate(2003) rate(2004) rate(2005) gdp inc unemp_rate, ///trunit(12) trperiod(2010) fig keep(spec_5.dta, replace) unitnames(state)synth rate rate(1999) rate(2001) rate(2002) rate(2003) gdp inc unemp_rate, ///trunit(12) trperiod(2010) fig keep(spec_6.dta, replace) unitnames(state)We can extract the information regarding variable weights to probe how muchimportance is given to each predictor in the model (this is based on theirpredictive power). In the model using the entire range of outcome years,the covariate weights for gdp inc and unemp_rate will be set to 0 (and arehence redundant). Choosing one of the other model optionsis likely preferable in cases when other covariates are included.The main output tells us the unit weights and predictor balance,but omits the variable weights. However, the variable weight matrixcan still be extracted after estimation using:Which gives the results for the lastest model estimated. Now checkto compare against the model that matches on all years:qui synth rate rate(1999) rate(2000) rate(2001) rate(2002) rate(2003) rate(2004) rate(2005) rate(2006)rate(2007) rate(2008) rate(2009) gdp inc unemp_rate, ///trunit(12) trperiod(2010)matlist e(V_matrix) //the variable weights for gdp, inc and unemp_rate are now = 0_________________________________________________________________________Section 2: Main analysis.Run synth to perform the main analysis as presented in the paper.__________________________________________________________________________Here we match on the outcome itself (every even year in the pre-interventionperiod) and the pre-intervention averages of gdp, inc and unemp_rate. We exploreother options below, but for now: this is the model with the best pre-interventionfit, as measured by the RMSPE (lower=better).synth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, ///trunit(12) trperiod(2010) fig keep(main_res.dta, replace) unitnames(state)________________________________________________________________________________Section 2: Inferential statistics as suggested by Abadie, Diamond and HeinmullerWe will now perform two placebo permutation tests (one graphical and oneThe graphical test gives us a hint regarding the distribution of placebo results from untreated states, but is sometimes hard to read.The other produces a pseudo p-value by ranking the states (placebo and Florida) according to their post/pre-intervention RMSPE ratio (larger ratio=bigger effect estimate irrespective of direction).________________________________________________________________________________This code runs through all units in the dataset and estimate a synthetic control unit for each one of them. It then stores and merges the results from all of these iterations (46 total), producing a new variable containing the difference between the observed values of outcome Y to the synthetic valuesof Y for every year in the time series. We define the variable as the estimated effect for unit i at time t.In the end, it plots the placebo results in gray against the main results for the treated unit (Florida) in black.NOTE: Make sure to run the entire loop at once.egen id = group(statecode)forvalues i = 1/46 { //change last number to number of units in the datatempfile synth_`i' //tempfile to store the results from model `i'qui synth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, ///trunit(`i') trperiod(2010) keep(`synth_`i'', replace)forvalues i = 1/46 { //change last number to number of units in the datagen tr_effect_`i' = _Y_treated - _Y_syntheticsave `synth_`i'', replaceforvalues i = 2/46 { //change last number to number of units in the dataqui merge 1:1 years using `synth_`i'', nogenerateforvalues i = 1/46{ //change last number to number of units in the data local lp `lp' line tr_effect_`i' years, lcolor(gs12) lpattern(solid) ||twoway `lp' || line tr_effect_9 years, ///lcolor(black) lpattern(solid) legend(off) xline(2010, lpattern(dash) lcolor(black)) ylab(,nogrid)(1) Change "line tr_effect_9" to tr_effect_[treatunit] to highlight other treatmentunits in the plot. Also, change xline([year],...) to the intervention year.In the paper, I use the resulting dataset (now in use) to generate Fig. 4, whichalso highlights the placebos with the same or greater post/pre-RMSPE ratio. I use anexternal plotting program for this, although code can easily be added tothe twoway plot above to highlight specific placebos. (2) The forvalues loop is only valid if id codes are in consecutive order.If not, generate a new id var using "egen newid = group(oldid)" and identifyvalue of the treatment unit on the new id variable and the change input valuesindicated in the code above. (This is not a problem in this dataset)*************************************************"PSEUDO P-VALUES" AND POST/PRE RMSPE RATIOS*************************************************Next, let's calculate a pseudo p-value based on the rank of the treatment unit'spost/pre-RMSPE ratio compared to the untreated placebo units post/pre-RMSPEratios (as in Abadie, Diamond and Heinmuller 2010, referenced in the paper).We use the placebo effect dataset genereted by the code above for this,so the code for the spaghetti plot above must be run first.replace post = 1 if years>=2010 //change intervention year if neededforvalues i = 1/46 { //change last number to to number of units/panels in the datagen error_squared_`i' = (tr_effect_`i')^2collapse (mean) error_squared_*, by(post)reshape long error_squared_, i(post) j(id)reshape wide error_squared_, i(id) j(post)gen rootpre = sqrt(error_squared_0)gen rootpost = sqrt(error_squared_1)gen Ratio = rootpost/rootpresummarize Ratio if id==9, meanonly //change id to treatunitscalar treatRMSPE = r(mean)replace prob = 1 if Ratio>=treatRMSPEtempname resmat //list post/pre ratios for all units forvalues i = 1/46 { //change last number to to number of units/panels in the datasummarize Ratio if id==`i', meanonlymatrix `resmat' = nullmat(`resmat') \ r(mean) local names `"`names' `"`i'"'"' mat colnames `resmat' = "Post/Pre Ratio" mat rownames `resmat' = `names' matlist `resmat' , row("Temp ID")mat colnames pvalue = "p-value"mat rownames pvalue = "Ratio trunit"matlist pvalue //probability of finding post/pre ratio => ratio in treatment unit_______________________________________________________________________________Section 3: Sensitivity analysis (leave-one-out)_______________________________________________________________________________In this section, we run the leave-one-out sensitivity analysis as presentedin the paper. We begin by opening the analysis dataset again.*Define the incidence rate variable (per 100.000 population)gen rate = deaths/population*100000merge 1:1 state year using "Covariates\unemp_panel.dta", nogeneratemerge 1:1 state year using "Covariates\capita_gdp_panel.dta", nogeneratemerge 1:1 state year using "Covariates\personal_capita_income_panel.dta", nogenerate**Identify and drop states with missing outcome values (Synth doesn't likegen missing = missing(rate)by statecode (missing), sort: drop if missing[_N]==1*Tell Stata that the data is a panel dataset***************************************LEAVE ONE OUT**************************************This procedure can get a little tedious as we will do it by hand,checking the pre-intervention RMSPE for each model, and iterativelyremoving the state that recieved the largest weight in the previousiteration. As we saw in the main analysis, Maine was the largestcontributor to the synthetic control unit. As such, we begin bydropping Maine from the donor pool. In iteration 2, we will noticethat Hawaii is the largest contributor, so iteration 3 will dropboth Maine and Hawaii, etc, until we obtain a model with twicethe prediction errors as in the main analysis (RMSPE for the main analysisis 0.55, so we will keep going until it is >1.10. Turns outthis results in 35 iterations before we stop. (In an ideal case,we would probably be better off by writing a algorithm thatsynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_1.dta, replace)**Drop Hawaii & Maine (Iter 2)drop if state=="Hawaii"|state=="Maine"synth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_2.dta, replace)**Drop Pennsylvania, Hawaii & Maine (Iter 3)drop if state=="Pennsylvania"|state=="Hawaii"|state=="Maine"synth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_3.dta, replace)**Drop Arkansas,Pennsylvania, Hawaii & Maine (Iter 4)drop if state=="Arkansas"|state=="Pennsylvania"|state=="Hawaii"|state=="Maine"synth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_4.dta, replace)**Drop Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 5)drop if state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaii"|state=="Maine"synth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_5.dta, replace)**Drop Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 6)state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaii"|state=synth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_6.dta, replace)**Drop NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 7)Jersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_7.dta, replace)**Drop Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 8)drop if state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_8.dta, replace)**Drop Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 9)drop if state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_9.dta, replace)**Drop New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 10)drop if state=="New Hampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_10.dta, replace)**Drop Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii &drop if state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="New Jersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_11.dta, replace)**Drop Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii &drop if state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_12.dta, replace)**Drop Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania,drop if state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_13.dta, replace)**Drop Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali,Arkansas,Pennsylvania, Hawaii & Maine (Iter 14)drop if state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_14.dta, replace)**Drop Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali,Arkansas,Pennsylvania, Hawaii & Maine (Iter 15)state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_15.dta, replace)**Drop Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali,Arkansas,Pennsylvania, Hawaii & Maine (Iter 16)state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="New Hampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_16.dta, replace)**Drop Louisiana, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ,Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 17)state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="New Hampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_17.dta, replace)**Drop Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ,Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 18)state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_18.dta, replace)**Drop Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia,NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 19)state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="New Jersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_19.dta, replace)**Drop Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland,Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 20)state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_20.dta, replace)**Drop NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp.,Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 21)Carolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_21.dta, replace)**Drop Nevada, NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp.,Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 22)drop if state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_22.dta, replace)**Drop Tennessee, Nevada, NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing,New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 23)drop if state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_23.dta, replace)**Drop Connecticut, Tennessee, Nevada, NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas,Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Mainedrop if state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_24.dta, replace)**Drop Minnesota, Connecticut, Tennessee, Nevada, NC, Ohio, Montana, Alabama, Utah, Georgia,Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania,drop if state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_25.dta, replace)**Drop Delaware, Minnesota, Connecticut, Tennessee, Nevada, NC, Ohio, Montana, Alabama, Utah,Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali,Arkansas,Pennsylvania, Hawaii & Maine (Iter 26)state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|stCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="New Jersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_26.dta, replace)**Drop Massachusetts, Delaware, Minnesota, Connecticut, Tennessee, Nevada, NC, Ohio, Montana,Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali,Arkansas,Pennsylvania, Hawaii & Maine (Iter 27)state=="Massachusetts"|state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_27.dta, replace)**Drop Colorado, Massachusetts, Delaware, Minnesota, Connecticut, Tennessee, Nevada, NC, Ohio,Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia, NJ,Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 28)state=="Colorado"|state=="Massachusetts"|state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_28.dta, replace)**Drop Iowa, Colorado, Massachusetts, Delaware, Minnesota, Connecticut, Tennessee, Nevada, NC,Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland, Virginia,NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 29)state=="Iowa"|state=="Colorado"|state=="Massachusetts"|state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_29.dta, replace)**Drop Indiana, Iowa, Colorado, Massachusetts, Delaware, Minnesota, Connecticut, Tennessee, Nevada,NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, New Hamp., Maryland,Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 30)state=="Indiana"|state=="Iowa"|state=="Colorado"|state=="Massachusetts"|state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_30.dta, replace)**Drop Wisconsin, Indiana, Iowa, Colorado, Massachusetts, Delaware, Minnesota, Connecticut,Tennessee, Nevada, NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, NewHamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 31)state=="Wisconsin"|state=="Indiana"|state=="Iowa"|state=="Colorado"|state=="Massachusetts"|state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=Carolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_31.dta, replace)**Drop Illinois, Wisconsin, Indiana, Iowa, Colorado, Massachusetts, Delaware, Minnesota, Connecticut,Tennessee, Nevada, NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz., Washing, NewHamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iter 32)state=="Illinois"|state=="Wisconsin"|state=="Indiana"|state=="Iowa"|state=="Colorado"|state=="Massachusetts"|state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state==Carolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_32.dta, replace)**Drop Vermont, Illinois, Wisconsin, Indiana, Iowa, Colorado, Massachusetts, Delaware, Minnesota,Connecticut, Tennessee, Nevada, NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas, Ariz.,Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Maine (Iterstate=="Vermont"|state=="Illinois"|state=="Wisconsin"|state=="Indiana"|state=="Iowa"|state=="Colorado"|state=="Massachusetts"|state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_33.dta, replace)**Drop Missi., Vermont, Illinois, Wisconsin, Indiana, Iowa, Colorado, Massachusetts, Delaware,Minnesota, Connecticut, Tennessee, Nevada, NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas,Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Mainestate=="Mississippi"|state=="Vermont"|state=="Illinois"|state=="Wisconsin"|state=="Indiana"|state=="Iowa"|state=="Colorado"|state=="Massachusetts"|state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_34.dta, replace)**Drop Missouri, Missi., Vermont, Illinois, Wisconsin, Indiana, Iowa, Colorado, Massachusetts, Delaware,Minnesota, Connecticut, Tennessee, Nevada, NC, Ohio, Montana, Alabama, Utah, Georgia, Idaho, Texas,Ariz., Washing, New Hamp., Maryland, Virginia, NJ, Kansas, Cali, Arkansas,Pennsylvania, Hawaii & Mainestate=="Missouri"|state=="Mississippi"|state=="Vermont"|state=="Illinois"|state=="Wisconsin"|state=="Indiana"|state=="Iowa"|state=="Colorado"|state=="Massachusetts"|state=="Delaware"|state=="Minnesota"|state=="Connecticut"|state=="Tennessee"|state=="Nevada"|state=="NorthCarolina"|state=="Ohio"|state=="Montana"|state=="Alabama"|state=="Louisiana"|state=="Utah"|state=="Georgia"|state=="Idaho"|state=="Texas"|state=="Arizona"|state=="Washington"|state=="NewHampshire"|state=="Maryland"|state=="Virginia"|state=="NewJersey"|state=="Kansas"|state=="California"|state=="Arkansas"|state=="Pennsylvania"|state=="Hawaiisynth rate rate(2000) rate(2002) rate(2004) rate(2006) rate(2008) gdp inc unemp_rate, trunit(12)trperiod(2010) unitnames(state) fig keep(loo_35.dta, replace)keep years _Y_treated _Y_syntheticrename _Y_treated observedrename _Y_synthetic loo_1forvalues i = 2/35 { //change last number to number of leave one out-iterationsrename _Y_synthetic loo_`i'forvalues i = 2/35 { //change last number to number of leave one out-iterationsqui merge 1:1 years using loo_`i', nogenerateforvalues i = 1/35{ //change last number to number of leave one out-iterations local lp `lp' line loo_`i' years, lcolor(gs12) lpattern(solid) ||twoway `lp' || line observed years, ///lcolor(black) lpattern(solid) legend(off) xline(2010, lpattern(dash) lcolor(black)) ylab(,nogrid)下面这些短链接文章属于合集,可以收藏起来阅读,不然以后都找不到了。