楼主: steeds
1434 4

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

  • 1关注
  • 1粉丝

已卖:2份资源

讲师

91%

还不是VIP/贵宾

-

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

受到警告 楼主
steeds 发表于 2014-1-15 01:01:04 |AI写论文
提示: 受到警告  蓝色 违反论坛规定 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
拉您入交流群
GMT+8, 2025-12-31 01:56