黃河泉 发表于 2019-1-4 06:59 
你若要问程序,永远附上相关资料;若附上资料,永远用 dataex 印出资料。
1. 先 ssc install dataex (并 ...
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input long id int year long p
2279 2009 .
2279 2010 4
2279 2011 .
2279 2012 4
2279 2013 4
2279 2014 4
2279 2015 4
2279 2016 4
2280 2009 .
2280 2010 .
2280 2011 19
2280 2012 19
2280 2013 19
2280 2014 19
2280 2015 19
2280 2016 19
2281 2009 21
end
其中id是公司代码,year是年份, p是公司注册地(不随时间改变),想要达到如下填充结果
input long id int year long p
2279 2009 4
2279 2010 4
2279 2011 4
2279 2012 4
2279 2013 4
2279 2014 4
2279 2015 4
2279 2016 4
2280 2009 19
2280 2010 19
2280 2011 19
2280 2012 19
2280 2013 19
2280 2014 19
2280 2015 19
2280 2016 19
2281 2009 21
end
尝试过bysort id :replace p=p[_n-1] if p==.和bysort id :replace p=p[_n+1] if p==.以及bysort id year:replace p=p[_n+1] if p==. 都无法实现。