全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
38013 4
2015-07-21
因为数值型原先有7位的(long),如何在变为string时补全为8位。
question2:在处理海关数据hs_id时,有的变为字符型,有的变为数值型(前面缺失一个0),出现上述情况时,有什么方法可以让两者保持一致?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-7-21 09:30:36
可以先转换成7位的string,然后把length不足8的用0补足
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-21 10:23:00
夏目贵志 发表于 2015-7-21 09:30
可以先转换成7位的string,然后把length不足8的用0补足
恩恩 就是这个意思 具体用什么命令 可否一说
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-21 11:03:15
https://bbs.pinggu.org/thread-1072521-1-1.html
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-21 11:16:41
看帮助的选项的介绍啊。不会看帮助,不会用maunal是学不会stata的。


tostring y, replace  format(%08.0f)







Title


    [D] destring -- Convert string variables to numeric variables and vice versa




Syntax


    Convert string variables to numeric variables


        destring [varlist] , {generate(newvarlist)|replace} [destring_options]




    Convert numeric variables to string variables


        tostring varlist , {generate(newvarlist)|replace} [tostring_options]




    destring_options         Description
    -------------------------------------------------------------------------------------
    * generate(newvarlist)   generate newvar_1, ..., newvar_k for each variable in
                               varlist
    * replace                replace string variables in varlist with numeric variables
      ignore("chars")        remove specified nonnumeric characters
      force                  convert nonnumeric strings to missing values
      float                  generate numeric variables as type float
      percent                convert percent variables to fractional form
      dpcomma                convert variables with commas as decimals to period-decimal
                               format
    -------------------------------------------------------------------------------------
    * Either generate(newvarlist) or replace is required.


    tostring_options         Description
    -------------------------------------------------------------------------------------
    * generate(newvarlist)   generate newvar_1, ..., newvar_k for each variable in
                               varlist
    * replace                replace numeric variables in varlist with string variables
      force                  force conversion ignoring information loss
      format(format)         convert using specified format
      usedisplayformat       convert using display format
    -------------------------------------------------------------------------------------




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群