全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
1838 1
2014-02-19
merge 以后。请问如何向前向后保留行数据
例:需要取合并成功年份之前一年和后三年的数据
code      year            month    _merge
1              1999           6             1
1              1999          12           1
1              2000           6             1
1              2000         12           1
.....
4             1999           6             1
4              1999          12             1
4             2000          6             3
4              2000         12            3
4             2001          6             1
4             2001           12             1

二维码

扫码加我 拉你入群

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

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

全部回复
2014-2-19 22:10:40
I think you can use another merge (not tested), just an idea (if by year only, not month):

tempfile f1 f2
save `f1'
keep if _merge==3
drop _merge month
duplicates drop
expand 5
sort code year, stable
by code year : replace year=year+_n-2
sort code year
save `f2'
use `f1'
drop _merge
sort code year
merge code year using `f2'
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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