did stata代码
时间: 2023-10-07 15:12:32 浏览: 311
以下是使用Stata编写的DID(双重差分)回归代码的示例:
引用\[1\]:
```
gen period = (year>=1994) & !missing(year) // 生成时间虚拟变量,1994年前为0,反之为1
gen treat = (country>4) & !missing(country) // 生成区域的虚拟变量,干预为1,反之为0
gen did = period * treat // 生成交叉项
reg y period treat did, r // DID回归:reg方式
```
引用\[2\]:
```
gen period = (year>=1992) & !missing(year) // 生成时间虚拟变量,1992年前为0,反之为1
gen treat = (country>4) & !missing(country)
gen did = period * treat
reg y period treat did x1-x3 i.opinion i.country, r
```
引用\[3\]:
```
gen period = (year>=1994) & !missing(year) // 生成时间虚拟变量,1994年前为0,反之为1
gen treat = (country>4) & !missing(country)
gen did = period * treat
gen policy = year - 1994
forvalues i = 4(-1)1 {
gen pre_`i' = (policy == -`i' & treat == 1)
}
xtreg y pre_*, fe r
est sto reg
coefplot reg, keep(pre_*) vertical recast(connect) yline(0)
```
希望这些代码能够帮助你进行DID回归分析。
#### 引用[.reference_title]
- *1* *2* *3* [双重差分法(DID):标准化流程和stata代码实现](https://blog.csdn.net/taozibaby/article/details/129649122)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文