检查重复组合
duplicates report id year
去掉重复得行
duplicates drop id year, force
合并数据
merge 1:1 id year using "C:\Users\Administrator\Desktop\3_cleaned.dta"
删除A没有的,但是B有
drop if _merge==2
drop _merge
给缺失值填充0
replace treatpost = 0 if missing(treatpost)
保留特定年份的数据
keep if year>=2010
保留特定的数据
keep code year age IndependentDirectorNumber1 IndependentDirectorNumber2 Bdnum_4 roa F011201A Seperation top5_HHI F061801B F010101A A001212000 tobin TFP_OP TFP_LP TFP_OLS TFP_FE TFP_GMM
重命名
rename code id
检查变量类型
describe id
将字符串变量转换为数值变量
destring id, replace force
将数值变量转换为双精度类型
recast double id
再次检查变量类型
describe id
统计数目
count if treatpost!=0
统计不重复的
gen flag = (treatpost == 1)
egen unique_ids = tag(id) if flag == 1
quietly count if unique_ids == 1
local num_unique_ids = r(N)
display `num_unique_ids'