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]
Re: st: lag variable in panel if missing data
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: lag variable in panel if missing data
Date
Tue, 4 Dec 2012 13:18:19 +0000
I think the short answer is that there is nothing automatic here. You
need to invent your own work-around, e.g.
364 days ago
if that is missing {
average of (363, 365 days ago)
if that is missing {
....
}
}
...
The easiest may be to average values for a week about a year ago. For
more on working with weeks, see
SJ-12-3 dm0065 . . . . . . . . . . Stata tip 111: More on working with weeks
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q3/12 SJ 12(3):565--569 (no commands)
discusses how to convert data presented in yearly and weekly
form to daily dates and how to aggregate such data to months
or longer intervals
SJ-10-4 dm0052 . . . . . . . . . . . . . . . . Stata tip 68: Week assumptions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q4/10 SJ 10(4):682--685 (no commands)
tip on Stata's solution for weeks and on how to set up
your own alternatives given different definitions of the
week
Nick
On Tue, Dec 4, 2012 at 1:10 PM, thomas bourveau
<[email protected]> wrote:
> I am currently working with a dataset where I have a company ID, the
> date, and a consumption variable.
>
> I am working in panel and, for each day, I need to generate a variable
> that is the difference between the current value of consumption, and
> its value one year before. (It's like an annual change).
>
> This stata code looks like that:
>
> generate difference = consumption - l364.consumption
>
> The issue is that my dataset is built using calendar days. Thus, very
> often, the l.364.consumption is nul because firms do not produce /
> spend money during the week-ends.
>
> I was wondering if it exists a command in panel that would
> automatically tell stata to take the closest existing variable if
> l364.consumption is nul. Can I also restrict that to a limited number
> of days (e.g 3 or 5 days before the current date) ?
*
* 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/