哇,楼上提供的这个好神奇啊,太谢谢了。我用了以后,激动地跳了起来,哇,太棒了。谢谢,谢谢。
楼上的真是高手啊。能不能再帮我看看一个问题?如下,
公司名 year data6 data19 data 21
a 1992 23 34 .
a 1993 34 35 .
a 1994 23 4 5
b 1992 23 5 .
b 1993 3 4 6
b 1994 5 2 7
当 a 公司的data21在1992年和1993年缺失时,想把1994年的数据值赋给1992年和1993年。请问怎么实现啊,谢谢大侠!!
也就是要把上面的数据改成
公司名 year data6 data19 data 21
a 1992 23 34 5
a 1993 34 35 5
a 1994 23 4 5
b 1992 23 5 6
b 1993 3 4 6
b 1994 5 2 7
自己解答这个问题,嘻嘻。刚刚在stata的网站上找到了类似的帮助信息,
How can I replace missing values with previous or following nonmissing values or within sequences?
Without tsset: copying nonmissing values
Let us first look at the case where you have not tsset your data (see, for example, [TS] tsset for an explanation), but we will assume that the data have been put in the correct sort order, say, by typing
. sort time
If missing values occurred singly, then they could be replaced by the previous value
. replace myvar = myvar[_n-1] if missing(myvar)
or by the following value
. replace myvar = myvar[_n+1] if missing(myvar)
Here the subscript notation used is that _n always refers to any given observation, _n−1 to the previous observation and _n+1 to the following observation, given the current sort order. There is not, of course, any observation before the first, or after the last, so myvar[0] is always missing, as is myvar for any observation number that is negative or greater than the number of observations in the data.
[此贴子已经被作者于2008-8-25 20:48:44编辑过]


雷达卡


京公网安备 11010802022788号







