请选择 进入手机版 | 继续访问电脑版
按年份索引
按国、省、市索引
综合索引
-->
返回列表
提升主题| 本版置顶| 关闭主题| 变更主题颜色| 抢沙发| 顶贴| 道具中心
楼主: liuyangclick
24041 38

[数据软件处理] 小白VS中国工业企业数据库(2):数据匹配前处理 [推广有奖]

xianghuowu 发表于 2019-10-28 23:29:11 |显示全部楼层 |坛友微信交流群
你好,新手小白想问一下,这一步是要把所有的字符串变量转化为数字格式吗?既然第三步需要用的匹配变量是字符串的,为什么还要进行这一步呢?不是很能理解,希望楼主能帮忙解答一下,十分感谢!

使用道具

niechu7717 发表于 2020-4-3 14:44:41 |显示全部楼层 |坛友微信交流群
morgenlicht1998 发表于 2019-9-4 19:13
谢谢分享!但是我碰到了一个问题,不知是否有朋友可以为我解答~就是我根据数据修改了这个代码,跑出来总是 ...
destring后面要加replace force

使用道具

275080365 发表于 2020-9-12 19:08:23 |显示全部楼层 |坛友微信交流群
x already defined 这是为什么?

使用道具

275080365 发表于 2020-9-12 19:32:12 |显示全部楼层 |坛友微信交流群
飞儿2015 发表于 2018-3-5 17:12
利用describe 命令,可以查看变量属性,之后修改非字符型变量,再应用楼主的程序就可以了。我也在学习过程 ...
我也想请教一下,我真的完全不懂,为什么会出来type mismatch。把那几个变量转换成数值型了也还是不行。。。

使用道具

alige99 发表于 2020-10-7 18:32:00 |显示全部楼层 |坛友微信交流群
谢谢分享!但是我碰到了一个问题,不知是否有朋友可以为我解答~就是我根据数据修改了这个代码,跑出来总是显示
foreach command may not result from a macro expansion in
> teractively or in do files
r(198);

我的代码如下:
use `"D:\中国工业企业数据库-相关\original_1998.dta"',clear
. global vars "region_code zip telephone cic founding_year founding_month"
. qui foreach v of varlist $vars{
. gen x=`v'
. destring x ,replace force
. gen n=.
. forv i=1/`=r(width)'{
. replace n=indexnot(x,"0123456789")
. replace x=substr(x,1,n-1)+substr(x,n+1,.)
. }
. gen z=real(x)
. drop x n
. rename z `v'1
. }

使用道具

alige99 发表于 2020-10-8 11:36:02 |显示全部楼层 |坛友微信交流群
  1. global vars "region_code zip telephone cic founding_year founding_month"
  2. set trace on
  3. quietly foreach v of varlist $vars{
  4. gen x=`v'
  5. destring x ,replace force
  6. gen n=.
  7. forv i=1/`=r(width)'{
  8. replace n=indexnot(x,"0123456789")
  9. replace x=substr(x,1,n-1)+substr(x,n+1,.)
  10. }
  11. gen z=real(x)
  12. drop x n
  13. rename z `v'1
  14. }
复制代码


加入set trace on 之后,出现如下结果
  1. - capture drop ``varmac''
  2.   = capture drop __000001
  3.   - }
  4.   - capture drop ``varmac''
  5.   = capture drop __000002
  6.   - }
  7.   - capture drop ``varmac''
  8.   = capture drop __000003
  9.   - }
  10.   - capture drop ``varmac''
  11.   = capture drop __000004
  12.   - }
  13.   - }
  14.   - }
  15.   -------------------------------------------- end destring ---
  16. - gen n=.
  17. - forv i=1/"=r(width)"{
  18. invalid syntax
  19.   replace n=indexnot(x,"0123456789")
  20.   replace x=substr(x,1,n-1)+substr(x,n+1,.)
  21.   }
  22. r(198);

  23. end of do-file

  24. r(198);
复制代码


请问有谁能告诉我怎么修改代码才能顺利运行吗?谢谢!

使用道具

alige99 发表于 2020-10-9 21:15:21 |显示全部楼层 |坛友微信交流群
morgenlicht1998 发表于 2019-9-4 19:13
谢谢分享!但是我碰到了一个问题,不知是否有朋友可以为我解答~就是我根据数据修改了这个代码,跑出来总是 ...
您好,请问,forv i=1/`=r(width)' 是起到什么作用的呀在这段程序里面?这程序是用单引号把等号也括在里面吗?还是怎样的?我把这段程序根据实际情况修改运行到r(width)这里识别不了了……麻烦你抽空帮忙解答一下可以吗。感谢!

使用道具

姜小花花 学生认证  发表于 2021-1-13 11:11:42 |显示全部楼层 |坛友微信交流群
275080365 发表于 2020-9-12 19:32
我也想请教一下,我真的完全不懂,为什么会出来type mismatch。把那几个变量转换成数值型了也还是不行。。 ...
不知道您后来怎么处理的,我也是转换为数值型依旧显示Mismatch

使用道具

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

本版微信群
加JingGuanBbs
拉您进交流群

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

GMT+8, 2024-3-28 22:24