其他
软件应用 | 政策评估利剑:合成控制法的Stata操作
The following article is from 功夫计量经济学 Author 江河JH
❝本文转载自公众号:功夫计量经济学
❞
❝「原文信息」
Alberto Abadie, Diamond A, Hainmueller J. Synthetic Control Methods for Comparative Case Studies: Estimating the Effect of California's Tobacco Control Program[J]. Journal of the American Statistical Association, 2010.
❞
政策背景
数据说明
state
(州)、year
(年)、cigsale
(人均香烟消费量,包/年)、lnincome
(人均收入对数)、beer
(人均啤酒消费量)、age15to24
(15-24岁人口所占总人口比重)、retprice
(平均香烟零售价格)。. use smoking,clear
(Tobacco Sales in 39 US States)
. xtset state year
Panel variable: state (strongly balanced)
Time variable: year, 1970 to 2000
Delta: 1 unit
. describe
Contains data from smoking.dta
Observations: 1,209 Tobacco Sales in 39 US States
Variables: 7 11 Nov 2007 23:38
-------------------------------------------------------------------------------------------------
Variable Storage Display Value
name type format label Variable label
-------------------------------------------------------------------------------------------------
state long %14.0g state state no
year float %9.0g year
cigsale float %9.0g cigarette sale per capita (in packs)
lnincome float %9.0g log state per capita gdp
beer float %9.0g beer consumption per capita
age15to24 float %9.0g percent of state population aged 15-24 years
retprice float %9.0g retail price of cigarettes
-------------------------------------------------------------------------------------------------
Sorted by: state year
合成控制法操作
synth cigsale retprice lnincome age15to24 beer ///
cigsale(1975) cigsale(1980) cigsale(1988),trunit(3) ///
trperiod(1989) xperiod(1980(1) 1988) figure ///
keep(smoking_synth,replace)
cigsale
为结果变量,retprice
、lnincome
、age15to24
、beer cigsale(1975)
、cigsale(1980)
和cigsale(1988)
为预测变量。trunit(#)
用于指定处理地区 ,trunit(3)
表示第3个州(即California加州)为处理组 。trperiod(#)
用于指定政策干预开始的时期,trperiod(1989)
表示政策开始实施时间为1989年。xperiod(numlist)
用于指定将预测变量进行平均的期间,默认为政策干预开始之前的所有时期。figure
表示将处理地区与合成控制的结果变量画时间趋势图。keep(smoking_synth)
将估计结果(比如,合成控制的权重、结果变量)存为另一Stata数据集(smoking_synth),以便进行后续计算。权重表
Unit Weights:
----------------------------
Co_No | Unit_Weight
---------------+------------
Alabama | 0
Arkansas | 0
Colorado | .356
Connecticut | .083
Delaware | 0
Georgia | 0
Idaho | 0
Illinois | 0
Indiana | 0
Iowa | 0
Kansas | 0
Kentucky | 0
Louisiana | 0
Maine | 0
Minnesota | 0
Mississippi | 0
Missouri | 0
Montana | 0
Nebraska | 0
Nevada | .217
New Hampshire | 0
New Mexico | 0
North Carolina | 0
North Dakota | 0
Ohio | 0
Oklahoma | 0
Pennsylvania | 0
Rhode Island | 0
South Carolina | 0
South Dakota | 0
Tennessee | 0
Texas | 0
Utah | .344
Vermont | 0
Virginia | 0
West Virginia | 0
Wisconsin | 0
Wyoming | 0
----------------------------
平衡性检验
Predictor Balance:
------------------------------------------------------
| Treated Synthetic
-------------------------------+----------------------
retprice | 89.42222 89.00128
lnincome | 10.07656 9.904773
age15to24 | .1735324 .175389
beer | 24.28 23.26454
cigsale(1975) | 127.1 126.3862
cigsale(1980) | 120.2 120.7221
cigsale(1988) | 90.1 92.0883
------------------------------------------------------
合成控制图
计算控烟法的处理效应
use smoking_synth.dta, clear
gen effect= _Y_treated - _Y_synthetic
label variable _time "year"
label variable effect "处理效应"
line effect _time, xline(1989,lp(dash)) yline(0,lp(dash))![](C:\Users\江河\Desktop\加州控烟数据与代码\02.png)
安慰剂检验
**对每一个州进行合成控制估计
tempname resmat //设定一个临时矩阵叫做resmat
forval i=1/39{
qui synth cigsale retprice lnincome age15to24 beer cigsale(1975) cigsale(1980) cigsale(1988),trunit(`i') trperiod(1989) xperiod(1980(1) 1988) keep(smoking_synth_`i',replace)
matrix `resmat' = nullmat(`resmat') \ e(RMSPE) //矩阵用来存放每个州进行合成控制的rmspe值
local names `"`names' `"`i'"'"'
}
mat colnames `resmat' = "RMSPE" //矩阵的列名定义为RMSPE
mat rownames `resmat' = `names' //矩阵的行名为names
matlist `resmat' , row("Treated Unit")
Treated Unit | RMSPE
-------------+-----------
1 | 2.710146
2 | 2.512085
3 | 2.03785
4 | 6.041637
5 | 5.216902
6 | 10.04986
7 | 1.38767
8 | 2.711447
9 | 3.307603
10 | 6.374926
11 | 3.994193
12 | 4.027571
13 | 26.14307
14 | 2.24033
15 | 4.162081
16 | 4.473659
17 | 2.520064
18 | 2.108559
19 | 2.356012
20 | 2.435734
21 | 7.71803
22 | 59.03776
23 | 2.42456
24 | 10.73793
25 | 4.562296
26 | 3.594593
27 | 3.2714
28 | 2.960468
29 | 12.75254
30 | 1.784269
31 | 3.154255
32 | 2.658026
33 | 2.678193
34 | 24.36728
35 | 9.442087
36 | 5.924654
37 | 3.208769
38 | 2.957548
39 | 10.68497
forval i=1/39{
use smoking_synth_`i', clear
rename _time years
gen tr_effect_`i' = _Y_treated - _Y_synthetic
keep years tr_effect_`i'
drop if missing(years)
save smoking_synth_`i', replace
}
**匹配到一张表
use smoking_synth_1, clear
forval i=2/39{
qui merge 1:1 years using smoking_synth_`i', nogenerate
}
**删除拟合不好的州
drop tr_effect_6 //删除Delaware
drop tr_effect_13 //删除Kentucky
drop tr_effect_22 //删除New Hampshire
drop tr_effect_24 //删除North Carolina
drop tr_effect_29 //删除Rhode Island
drop tr_effect_34 //删除Utah
drop tr_effect_35 //删除Vermont
drop tr_effect_39 //删除Wyoming
**处理效应图
local lp1
forval i=1/2 {
local lp1 `lp1' line tr_effect_`i' years, lpattern(dash) lcolor(gs8) ||
}
local lp2
forval i=4/5 {
local lp2 `lp2' line tr_effect_`i' years, lpattern(dash) lcolor(gs8) ||
}
local lp3
forval i=7/12 {
local lp3 `lp3' line tr_effect_`i' years, lpattern(dash) lcolor(gs8) ||
}
local lp4
forval i=23/23 {
local lp4 `lp4' line tr_effect_`i' years, lpattern(dash) lcolor(gs8) ||
}
local lp5
forval i=25/28 {
local lp5 `lp5' line tr_effect_`i' years, lpattern(dash) lcolor(gs8) ||
}
local lp6
forval i=30/33 {
local lp6 `lp6' line tr_effect_`i' years, lpattern(dash) lcolor(gs8) ||
}
local lp7
forval i=36/38 {
local lp7 `lp7' line tr_effect_`i' years, lpattern(dash) lcolor(gs8) ||
}
twoway `lp1' `lp2' `lp3' `lp4' `lp5' `lp6' `lp7'|| line tr_effect_3 years, ///
lcolor(black) legend(off) xline(1989, lpattern(dash)) yline(0,lp(dash)) ylabel(-30(15)45)
点击搜索你感兴趣的内容吧
往期推荐
数据Seminar
这里是大数据、分析技术与学术研究的三叉路口
推荐 | 青酱
欢迎扫描👇二维码添加关注