创建新文档
clear all
gl path C:\Download
mkdir "$path\input"
mkdir "$path\temp"
mkdir "$path\output"
当路径中含有空格时需用双引号引用路径
数据处理
中文乱码处理
clear
cd "D:\BaiduNetdiskDownload\"
unicode analyze 2009_append.dta
unicode encoding set gb18030
unicode translate 2009_append.dta,invalid
字符串与数值转换
字符串变数值
destring, replace
数值变成字符串
tostring,replace
字符串截取
gen isic3=substr(isic3_four,1,3)
字符串的替换与切割
替换
gen v1="this is the day"
*thH is the day*
gen v2= subinstr(v1,"is","X",1)
*thX X thX*
dis subinstr(v1,"is","X",.)
切割
gen v1="1 2 3"
split vq, gen(a)
gen v1="1,2,3"
split v2,p(",")gen (b)
循环转换excel to dta
forvalues j = 2015/2019{
import excel using `j'_expenditure_for_education.xlsx, clear firstrow
save `j'_expenditure_for_education.dta, replace
}
导入excel
import excel "D:\财政绩效专题\Finance budget\Inputs\地区代码转换表\ZGTJNJ\地区代码转换表.xlsx", sheet("Sheet1") firstrow clear
循环合并
use 2015_expenditure_for_education.dta, clear
forv j=2016/2019 {
append using `j'_expenditure_for_education.dta
}
计时
set rmsg on
删除数据
drop if 证券代码 ==""
宽面板变长面板
reshape long EPS ROE, i(证券代码) j(year)
例子:https://www.lianxh.cn/news/c48db52c26ba5.html
模型选择
高纬固定效应
reghdfe y , absorb(i.iyear i.ind_code i.ind_code#i.year) vce(cluster idcode)