将数据库下载的表格整理为面板数据:
reshape long CCEST , i( CountryName CountryCode ) j(year)
- 注意:要把首行改写成“CCEST2000”的格式,CountryName、CountryCode是不变项,year是新增项目
- 建议看silencedream的b站http://【stata实现长宽数据转换(reshape,gather,spread)】 https://www.bilibili.com/video/BV1rJ411h73k/?share_source=copy_web
有些数据显示格式错误,无法reshape:转换为string格式:
tostring RLEST2013 , format(%100.0g) replace
- 可以在导入excel的时候就打勾“全部转换为string”
- 同理还有转换为数值型的“destring”
- 如果是需要数值型,可以把excel换成csv,csv可以在导入stata时就选择数据转换为numerical
不同格式互换
- 把string换成long
-
destring x, replace recast long x
-
- destring/tostri