楼主: 卢冲
494 2

[统计软件与数据分析] 面板数据赋值求助 [推广有奖]

  • 3关注
  • 1粉丝

院士

23%

还不是VIP/贵宾

-

威望
0
论坛币
11093 个
通用积分
23.5793
学术水平
0 点
热心指数
3 点
信用等级
0 点
经验
4859 点
帖子
1807
精华
0
在线时间
1296 小时
注册时间
2011-7-6
最后登录
2024-4-27

楼主
卢冲 学生认证  发表于 2021-11-13 11:20:59 |只看作者 |坛友微信交流群|倒序 |AI写论文
199论坛币
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(policy_year number)
201611  1
201612  2
201701  3
201701  4
201701  5
201701  6
201702  7
201702  8
201703  9
201703 10
201703 11
201703 12
201703 13
201704 14
201704 15
201704 16
201705 17
201706 18
201707 19
201708 20
201708 21
201708 22
201711 23
201806 24
201812 25
201901 26
201912 27
end
[/CODE]
------------------ copy up to and including the previous line ------------------

Listed 27 out of 27 observations




数据有很多条,想实现对201701的number赋值为3,201702的number赋值为4,201703的number赋值为5。。。。。








关键词:面板数据 observations observation including generated
沙发
martial江湖 发表于 2021-11-14 21:39:56 |只看作者 |坛友微信交流群
首先需要提取出policy_year的前六位数字
tostring policy_year , g(policy_year_6) format(%04.0f)
replace policy_year_6 = substr(policy_year_6,1,6)
destring policy_year_6, replace
然后进行赋值
replace number = 3 if policy_year_6 == 201701
......

使用道具

藤椅
martial江湖 发表于 2021-11-14 21:45:36 |只看作者 |坛友微信交流群
先提取变量的前六位数字
tostring policy_year, g(id) format(%04.0f)
replace id = substr(id, 1,2)
destring id, replace
然后再分别对其赋值
replace number = 3 if id == 201701

使用道具

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

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

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

GMT+8, 2024-4-28 02:43