楼主: shentanming
1750 17

[编程问题求助] 将dta文件分割成N个Excel文件 [推广有奖]

  • 5关注
  • 1粉丝

硕士生

58%

还不是VIP/贵宾

-

威望
0
论坛币
688 个
通用积分
1.0016
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1954 点
帖子
94
精华
0
在线时间
217 小时
注册时间
2010-12-29
最后登录
2020-7-10

30论坛币
我有一份stata格式的dta文件,但是有几十万行,我想先转入到Excel中处理一下,然后再导回stata中合并。
现在问题是Excel支持的观测值行数少,而且我一次性处理几万条,容易死机。
问题是:如何将stata格式的dta文件几十万条观测值,分割成每几万条一个的Excel文件?


比如将下面10条stata观测值的dta文件分割成3个Excel文件?

  1. * Example generated by -dataex-. To install: ssc install dataex
  2. clear
  3. input int ID
  4. 1
  5. 2
  6. 3
  7. 4
  8. 5
  9. 6
  10. 7
  11. 8
  12. 9
  13. 10
  14. end
复制代码



最佳答案

黃河泉 查看完整内容

感谢 Andrew Musau 之提供
关键词:EXCEL DTA文件 exce xcel cel

回帖推荐

黃河泉 发表于6楼  查看完整内容

最近几天好像有人问类似问题,我还不会 (我相信应该是可以在 Stata 中做的),也没机会去问 (若有英文之类似例子 (自己编一下),我可以帮你问)!
沙发
黃河泉 在职认证  发表于 2019-11-12 09:18:32 |只看作者 |坛友微信交流群
shentanming 发表于 2019-11-12 10:45
刚发了英文例子,还在审核中,如果审核一直不通过,我就重新开一个帖子,其实那个上一个问题是我同学提的 ...
感谢 Andrew Musau 之提供
  1. levelsof keywords, local(names) sep(|) clean
  2. gen wanted= regexs(0) if regexm(address, "(`names')")
  3. replace wanted= "NULL" if wanted==""
复制代码
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
shentanming + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

使用道具

藤椅
黃河泉 在职认证  发表于 2019-11-12 09:58:18 |只看作者 |坛友微信交流群
我一般都不建议这样做,请问你要处理什么?

使用道具

板凳
shentanming 学生认证  发表于 2019-11-12 10:16:30 |只看作者 |坛友微信交流群
黃河泉 发表于 2019-11-12 09:58
我一般都不建议这样做,请问你要处理什么?
老师,您好。我需要检验dta文件中,某一列(如A列)是否包含有指定字符串,而指定字符串不是一个,是2000个。只要A列第一行(A1),包含2000个中的一个,就在B1返回1,如果A1不包含2000个指定字符串的任意1个,就返回0。

使用道具

报纸
shentanming 学生认证  发表于 2019-11-12 10:21:51 |只看作者 |坛友微信交流群
如下,数据中,包含 “人” 和 “中” 的返回1,并且在第三列,返回具体是包含“人”  还是“中”

* Example generated by -dataex-. To install: ssc install dataex
clear
input int qb09a
931
513
603
661
762
852
511
661
603
511
213
511
761
401
302
731
752
271
603
131
end
label values qb09a LABN
label def LABN 131 "地质勘探工程技术人员", modify
label def LABN 213 "会计人员", modify
label def LABN 271 "记者", modify
label def LABN 302 "一般机关干部", modify
label def LABN 401 "商业服务业中层", modify
label def LABN 511 "大田作物生产人员", modify
label def LABN 513 "园艺作物生产人员", modify
label def LABN 603 "技术工人", modify
label def LABN 661 "机械冷加工人员", modify
label def LABN 731 "电子器件制造人员", modify
label def LABN 752 "纺织人员", modify
label def LABN 761 "裁剪、缝纫人员", modify
label def LABN 762 "鞋帽制作人员", modify
label def LABN 852 "印刷操作人员", modify
label def LABN 931 "检验人员", modify
[/CODE]

使用道具

地板
shentanming 学生认证  发表于 2019-11-12 10:22:31 |只看作者 |坛友微信交流群
shentanming 发表于 2019-11-12 10:16
老师,您好。我需要检验dta文件中,某一列(如A列)是否包含有指定字符串,而指定字符串不是一个,是2000 ...
dataex实例见第四层

使用道具

7
黃河泉 在职认证  发表于 2019-11-12 10:23:42 |只看作者 |坛友微信交流群
shentanming 发表于 2019-11-12 10:16
老师,您好。我需要检验dta文件中,某一列(如A列)是否包含有指定字符串,而指定字符串不是一个,是2000 ...
最近几天好像有人问类似问题,我还不会 (我相信应该是可以在 Stata 中做的),也没机会去问 (若有英文之类似例子 (自己编一下),我可以帮你问)!

使用道具

8
shentanming 学生认证  发表于 2019-11-12 10:29:17 |只看作者 |坛友微信交流群
黃河泉 发表于 2019-11-12 10:23
最近几天好像有人问类似问题,我还不会 (我相信应该是可以在 Stata 中做的),也没机会去问 (若有英文之类 ...
刚才中文例子还在审核中,没有显示出来,我现在做一个英文例子

使用道具

9
shentanming 学生认证  发表于 2019-11-12 10:43:17 |只看作者 |坛友微信交流群
if "address" contain any one in the list of "keywords",the "YesorNo" report 1,and "whichword" report the the word in the list of "keywords"
if not,the "YesorNo" report 0,and "whichword" report "NULL".

  1. * Example generated by -dataex-. To install: ssc install dataex
  2. clear
  3. input str24 address str7 keywords int YesorNo str7 whichword
  4. "United States of America" "America" 1 "America"
  5. "shanxi province china"    "china"   1 "china"  
  6. "shanxi province china"    ""        1 "china"  
  7. "United States of America" ""        1 "America"
  8. "anhui province china"     ""        1 "china"  
  9. "United States of America" ""        1 "America"
  10. "shanxi province china"    ""        1 "china"  
  11. "United States of America" ""        1 "America"
  12. "United Kingdom(UK)"       ""        0 "NULL"   
  13. "United Kingdom(UK)"       ""        0 "NULL"   
  14. "east of Canada"           ""        0 "NULL"   
  15. "Canada west"              ""        0 "NULL"   
  16. end
复制代码


question.png (23.99 KB)

question.png

使用道具

10
shentanming 学生认证  发表于 2019-11-12 10:44:49 |只看作者 |坛友微信交流群
shentanming 发表于 2019-11-12 10:29
刚才中文例子还在审核中,没有显示出来,我现在做一个英文例子
刚发了英文例子,还在审核中,如果审核一直不通过,我就重新开一个帖子,其实那个上一个问题是我同学提的,我们面临同一个问题~

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-25 17:06