楼主: steeds
1208 4

[编程问题求助] 求教如果检查一个string是否在另一堆string之中 [推广有奖]

  • 1关注
  • 1粉丝

讲师

91%

还不是VIP/贵宾

-

威望
0
论坛币
6687 个
通用积分
0.8509
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
319 点
帖子
142
精华
0
在线时间
1157 小时
注册时间
2009-5-9
最后登录
2023-5-16

提示: 受到警告  蓝色 违反论坛规定 2014-1-15 21:35
200论坛币
请教各位同学,假设数据如下

2001                             Bank of America
2001                             General Motors
2001                             General Elec
2002                             General Motors
2002                             General Elec
2003                             Goldman Sachs
2003                             General Elec

第一列是时间,第二列是当年的记录,每年记录数不同
现在我想检查每一年的各项记录是不是在上一年出现过,生成如下图第三列一样的新变量,该如何写呢?

2001                             Bank of America               
2001                             General Motors                  
2001                             General Elec                     
2002                             General Motors                1
2002                             General Elec                    1
2003                             Goldman Sachs               0
2003                             General Elec                    1

多谢了

关键词:string tring RING ING General General 记录 如何
Information Asymmetry|Market Microstructure|Credit Rating Agencies
沙发
jjjj6666 发表于 2014-1-15 06:45:51 |只看作者 |坛友微信交流群
sort by the 2nd column and compare using current row to previous row?

sort v2
gen v3=1 if v2==v2[_n-1] & v1==v1[_n-1]+1

使用道具

藤椅
steeds 发表于 2014-1-15 21:41:26 |只看作者 |坛友微信交流群
我想想。。
Information Asymmetry|Market Microstructure|Credit Rating Agencies

使用道具

板凳
hplcdadong 发表于 2014-1-15 22:05:22 |只看作者 |坛友微信交流群
Assume that each company only appear once each year, and in the following, even try to make your data a little more complex (there are gaps between years)

clear
input year str20 comp
2001  "Bank of America"
2001  "General Motors"
2001  "General Elec"
2002  "General Motors"
2002  "General Elec"
2003  "Goldman Sachs"
2003  "General Elec"
2008  "General Motors"
2009  "Goldman Sachs"
end

bysort comp (year): gen num=year[_n]-year[_n-1]
replace num=0 if num>1

使用道具

报纸
sungmoo 发表于 2014-1-19 12:00:52 |只看作者 |坛友微信交流群
sort year name /*如果数据天然排列齐整,此步可略*/
egen t=tag(name)

*t=1表示不重复,t=0表示重复。

使用道具

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

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

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

GMT+8, 2024-5-2 08:54