Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Foreach with leads and lags from numlist

    Hi there,

    I am sorry if this is a trivial question, but I did not seem to find a satisfactory answer.

    I have a housing transaction dataset which I am using for a difference-in-differences analysis. Part of it is the so-called 'Granger Causality Test', which uses to leads and lags to test a certain outcome. To calculate these I have housing characteristics, transaction year, and several difference-in-difference (DiD) variables (treated, treattime and did).

    I have DiD and treattime variables for each year in the numlist. How do I tell stata to take a value from the numlist - 1? I've tried it like this, but this doesn't work.

    Code:
    foreach num of numlist 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 {
        reg lnprice lnsize lnlotsize rooms i.trans_year treated treattime_`num' did_`num-3' did_`num-2' did_`num-1' did_`num+1' did_`num+2' did_`num+3'
        outreg2 using causalitytest, excel nose label cttop(`num')
    }
    Can anyone help me with this, or is it not possible?

    Thanks in advance!

  • #2
    However, Stata has a capability of using lags and leads, e.g.;

    Code:
    webuse grunfeld, clear
    
    foreach num of numlist 1939 1940 {
        reg invest mvalue L.mvalue L2.mvalue F.kstock F2.kstock if year==`num'
    }
    See also p4 of the tsset manual: https://www.stata.com/manuals13/tstsset.pdf

    It looks, however, that before you can use this, you will have to reshape your dataset from a wide to long format.
    If you want help with that, post a sample of your data with dataex; see section 12 of the FAQ for more on how and why: https://www.statalist.org/forums/help#stata

    Comment

    Working...
    X