Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: lag variable in panel if missing data


From   thomas bourveau <thomas.bourveau@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: lag variable in panel if missing data
Date   Tue, 4 Dec 2012 14:10:27 +0100

Dear readers,

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) ?

Thanks in advance

--
Thomas Bourveau
thomas.bourveau@gmail.com
0637573925
*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index