
全部利用Stata完成有点困难(但也不是一定不可以,只是最终程序应该会长挺多!)
以下的处理方法结合Excel-Word-Stata共同完成,处理思路和操作相对简单直观,希望楼主喜欢啦。
- // #0
- // 在Excel和Word中的手工数据预处理
- /*
- #0.1 将目标Excel工作表copy+paste至Word中
- #0.2 在Word中将手工回车符转换为特殊字符串,方便Stata的处理
- -> Ctrl-H(即“查找和替换”功能)
- -> 查找内容:^l
- -> 替换为:_***_
- -> 按“替换”键,完成查找替换任务
- #0.3 将查找替换后的Word表格内容copy+paste到新的Excel工作表中
- #0.4 将新的Excel工作表另存为“CSV(逗号分隔.csv)”,文件名为Example.csv
- */
- // #1
- // Stata中的处理
- // #1.1 导入csv文档
- insheet using Example.csv, clear comma names
- // #1.2 分隔变量
- split id, gen(nme) parse("_***_")
- split assignment, gen(asg) parse("_***_")
- // #1.3 转换为长型数据表并删除空值等
- keep number nme* asg*
- reshape long nme asg, i(number) j(rank)
- assert (!missing(nme) == !missing(asg))
- keep if !missing(nme)
- // #1.4 存盘
- save example, replace
- // Done!
Stata命令的.do文档以及手工预处理过程中生成的.docx和.csv文档:
Example.zip
(490.59 KB)
本附件包括:- Example.do
- Example.docx
- Example.csv


雷达卡




京公网安备 11010802022788号







