全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
2415 1
2014-02-05
year                city        data
2008                1        2
2008                2        4
2008                3        11
2009                1        5
2009                2        7
2009                3        10
2010                1        3
2010                2        8
2010                3        8

现在我想将2009和2010年city123的data都替换成2008年的数据,请问怎么做啊TAT
上面只是个例子,实际中city数目庞大
二维码

扫码加我 拉你入群

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

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

全部回复
2014-2-6 07:18:15
The easiest way I can think is to use merge, suppose the data is A and assuming city appears once per year

tempfile B C D
drop _all
use A
keep if year == 2008
sort city
drop year
save `B'

use A
keep if year == 2009
sort city
merge city using `B', update replace
drop _merge
save `C'

use A
keep if year == 2010
sort city
merge city using `B', update replace
drop _merge
save `D'

drop _all
use A
keep if year == 2008
append using `C' `D'
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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