楼主: bbads
38189 4

[字符问题求助] 怎样把stata中的数值型(long)变为字符型(str8),其中数值型有7位的。 [推广有奖]

  • 7关注
  • 3粉丝

已卖:7份资源

副教授

29%

还不是VIP/贵宾

-

威望
0
论坛币
957 个
通用积分
12.3988
学术水平
10 点
热心指数
20 点
信用等级
7 点
经验
16682 点
帖子
291
精华
0
在线时间
1141 小时
注册时间
2014-4-5
最后登录
2024-12-7

楼主
bbads 发表于 2015-7-21 09:21:27 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
因为数值型原先有7位的(long),如何在变为string时补全为8位。
question2:在处理海关数据hs_id时,有的变为字符型,有的变为数值型(前面缺失一个0),出现上述情况时,有什么方法可以让两者保持一致?
二维码

扫码加我 拉你入群

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

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

关键词:Stata tata long 数值型 字符型 字符型 数值型 stata

回帖推荐

蓝色 发表于5楼  查看完整内容

看帮助的选项的介绍啊。不会看帮助,不会用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 varia ...

本帖被以下文库推荐

沙发
夏目贵志 发表于 2015-7-21 09:30:36
可以先转换成7位的string,然后把length不足8的用0补足

藤椅
bbads 发表于 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
    -------------------------------------------------------------------------------------




已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
清华王雪纯 + 1 + 1 + 1 观点有启发
夏目贵志 + 20 + 20 + 5 + 5 + 5 这样更好

总评分: 经验 + 20  论坛币 + 20  学术水平 + 6  热心指数 + 6  信用等级 + 6   查看全部评分

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-9 03:45