Bookmark and Share

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: RE: Lag variables - generate missing values


From   David Ashcraft <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: RE: Lag variables - generate missing values
Date   Wed, 11 Jul 2012 05:25:57 -0700 (PDT)

Nick, Thanks. It was my bad, I need some of your detective skills. I could have saved more than 2 hours if I had look at the command properly. I formatted date as %tm without mofd. Anyway, It is working now.
Regards

David 


----- Original Message -----
From: Nick Cox <[email protected]>
To: "'[email protected]'" <[email protected]>
Cc: 
Sent: Wednesday, July 11, 2012 3:12:48 PM
Subject: st: RE: Lag variables - generate missing values

You have a strong clue from Stata that something is very off with your data. 

You say that you have dates from Jan 2000 to May 2010. 

In that case, why do they display as (e.g.) 3180m1 to 3555m5? 

Some small detective work leads to the conclusion that you have daily dates about a month apart, but you have _not_ converted them. You can't just say that you have monthly dates when you have daily dates. They must _be_ monthly dates. 

. di %tm 14640
3180m1

. di %tm 19144
3555m5

. di %td 14640
31jan2000

. di %td 19144
31may2012

In fact it seems that your data end in May 2012, not May 2010. 

You need to push your dates through -mofd()-. 

Nick 
[email protected] 

David Ashcraft

I am trying to generate a new variable by using the lag operator L. on a panel data set. When I use the lag operator, the generated variable return as ALL MISSING values. I am lost here. I have tried with old operator i.e. (_n-1) and the outcome is same. In my data set, id is the identifier and date1 is the date. Data is monthly from Jan2000 to may2010. 

I am using the following set of commands to generate the lag variable


. sort id date1

. tsset  id date1, monthly
panel variable:  id (unbalanced)
time variable:  date1, 3180m1 to 3555m5, but with gaps
delta:  1 month

. su rtn

Variable        Obs        Mean    Std. Dev.       Min        Max

rtn       2814    1624.403     1884.28      71.81   14132.85

. describe rtn date1 id

storage  display     value
variable name   type   format      label      variable label
rtn             float  %9.0g                  
date1           float  %tm                    
id              float  %9.0g                  

. gen return= ln(rtn/L.rtn)
(2814 missing values generated)

Any help will be highly appreciated.

*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index