Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Fill in values for year in an unbalanced panel with known order |

Date |
Tue, 23 Oct 2012 17:27:34 +0100 |

Fine; but -missing()- is a function, not an option. Nick On Tue, Oct 23, 2012 at 5:25 PM, Fernando Luco <flucoestatalist@gmail.com> wrote: > Thanks Nick, it worked perfectly. I didn't think about using the > 'missing()' option. > > Fernando > > On Tue, Oct 23, 2012 at 11:19 AM, Nick Cox <njcoxstata@gmail.com> wrote: >> This is a variation on a standard problem, on which see >> >> FAQ . . . . . . . . . . . . . . . . . . . . . . . Replacing missing values >> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox >> 1/12 How can I replace missing values with previous or >> following nonmissing values or within sequences? >> http://www.stata.com/support/faqs/data-management/ >> replacing-missing-values/ >> >> I suggest >> >> sort id, stable >> by id: replace year = cond(month == 1, year[_n-1] + 1, year[_n-1]) if >> missing(year) >> >> Nick >> >> On Tue, Oct 23, 2012 at 5:07 PM, Fernando Luco >> <flucoestatalist@gmail.com> wrote: >> >>> I'm trying to fill in the year of observations for which I know the >>> month and because of the order, I have no doubt about the year. >>> However, the year was not recorded. In particular, the data looks as >>> follows >>> >>> id year month >>> 1 1988 5 >>> 1 . 6 >>> 1 . 7 >>> 1 . 8 >>> 1 . 9 >>> 1 . 10 >>> 1 . 11 >>> 1 . 12 >>> 1 . 1 >>> 1 1989 2 >>> 1 1989 3 >>> 1 . 4 >>> 2 . 3 >>> 2 1989 4 >>> 2 1989 5 >>> 2 . 6 >>> 2 . 7 >>> 2 . 8 >>> 2 1989 9 >>> 2 . 10 >>> 2 . 11 >>> 2 . 12 >>> 2 . 1 >>> 2 1990 2 >>> 2 . 3 >>> >>> So, it is an unbalanced panel, that for each id might start and end at >>> a different year month combination, and I know that the order of the >>> observations within id is correct, so I'm sure that the first >>> observation for id==2 is of 1989 while the second observation that has >>> id==2 and month==3 (the last observation in the example) corresponds >>> to 1990. The main complication is that for some people I might have a >>> gap of more than one year between observations, which has made things >>> difficult. I would like to use the structure of the data to fill in >>> the data for year. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Fill in values for year in an unbalanced panel with known order***From:*Fernando Luco <flucoestatalist@gmail.com>

**Re: st: Fill in values for year in an unbalanced panel with known order***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Fill in values for year in an unbalanced panel with known order***From:*Fernando Luco <flucoestatalist@gmail.com>

- Prev by Date:
**Re: st: Fill in values for year in an unbalanced panel with known order** - Next by Date:
**Re: st: mi impute chained error messages** - Previous by thread:
**Re: st: Fill in values for year in an unbalanced panel with known order** - Index(es):