Another approach would be to use -tsappend- and -xfill- (net from
http://www.sealedenvelope.com/) For example:
(Also, in the second approach, I believe the -foreach- statement would need
to be written as: foreach y of num 1983 1986 1989 1990 1993 1994 1997 1998
2001/2004 { )
clear
input county fip year vbl
1 1 1980 .
1 1 1981 .
1 1 1982 .
1 1 1984 .
1 1 1985 .
1 1 1987 .
1 1 1988 .
1 1 1991 .
1 1 1992 .
1 1 1995 .
1 1 1996 .
1 1 1999 .
1 1 2000 .
3 1 1980 1
3 1 1981 1
3 1 1982 1
3 1 1984 0
3 1 1985 0
3 1 1987 0
3 1 1988 0
3 1 1991 0
3 1 1992 0
3 1 1995 0
3 1 1996 0
3 1 1999 0
3 1 2000 0
end
egen id = group(county fip)
tsset id year
tsappend, add(4)
xfill coun fip
Scott
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Nick Cox
> Sent: Friday, November 24, 2006 10:58 AM
> To: [email protected]
> Subject: RE: st: RE: help expanding the dataset by n observations
>
> OK, joking aside:
>
> We have two approaches to doing it. The
> comparison is interesting.
>
> (1) no change of data shape.
>
> (a) add extra pseudo-observations
> (b) -fillin-
> (c) drop extra pseudo-observations
>
> For what I recommended, you don't have to go into -edit-.
> Let's look at the all command version.
>
> set obs `= _N + 12'
> tokenize "1983 1986 1989 1990 1993 1994 1997 1998 2001 2002 2003 2004"
> forval i = 1/12 {
> replace year = ``i'' in -`i'
> }
> fillin fip county year
> drop if county == . | fip == .
>
> (2) change of data shape.
>
> (a) -reshape-
> (b) new variables
> (c) -reshape- back
>
> egen id=group(county fip)
> reshape wide vbl, i(id) j(year)
> foreach y of num 1983 1986 1989 1990 1993 1994 1997 1998 2001-2004 {
> gen vbl`y' = .
> }
> reshape long vbl, i(id) j(year)
> drop id
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/