Statalist


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

Re: st: Unable to create lag variables in a panel dataset


From   Steven Archambault <[email protected]>
To   [email protected]
Subject   Re: st: Unable to create lag variables in a panel dataset
Date   Fri, 14 Aug 2009 10:47:08 -0600

With 30,000 users and 22 months, that is a total of 726,000 possible
observations. Having only 100,000 missing values doesn't seem too bad.
You did say it was unbalanced, so not each value is going to have a
lag. If you want to fill in the missing data, one approach would be to
let a missing value take on the lag value. This is only one method to
fill in missing data.

replace totsol=l.totsol if totsol==





On Fri, Aug 14, 2009 at 10:38 AM, Jabr, Wael
M<[email protected]> wrote:
> I have a large unbalanced panel dataset that I collected. The panel variable is the userid (~30,000 users) and the time variable is the month (22 months). Both userid and month are numeric variables. All users do not have observations for each of the 22 months as some join later in the study. My dataset is in .dta format.
>
> I am trying to define lag variables but keep failing.
> I tried:
> sort userid month
> tsset userid month
>
> and alterbatively
> xtset userid month
>
> Then whenever I try to define a lag variable for the var totsol
> gen l1totsol = l1.totsol
> (100080 missing values generated)
>
> I thought there might be something wrong in my dataset and tried to use
> webuse abdata
> sort id year
> tsset id year
> (or xtset id year)
>
> Then whenever I try to generate the lag variable for the var n, I get missing values generated.
> gen l1n= l1.n
> (140 missing values generated)
>
> I also tried 2 other approaches with no avail
>
> . by id: gen lag1=wage[_n-1]
> (140 missing values generated)
>
>
> . by id: gen lag1 = wage[_n-1] if year==year[_n-1]+1
> (140 missing values generated)
>
>
> This kept me up all day and all night yesterday.
>
> Any help please?
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index