Announcement

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

  • lagging for gllamm

    I am going to be running multilevel (longitudinal) logistic regression using gllamm. I need to lag most of my variables by one year prior to performing this analysis. Important to note is that I need to lag by subject, which is Garden_ID_ . My data is currently in the "long" format. For simplicity, in this example I will need to lag Var 1 and Var2, but not var 3.

    Do I need to make new lagged variables to run gllamm, and if so what's the easiest way to do that?
    Garden_ID_ Year Var1 Var2 Var3
    1 2012
    1 2013
    1 2014
    1 2015
    2 2012
    2 2013
    2 2014
    2 2015
    Many thanks,
    Alyssa

  • #2
    My data is currently in the "long" format. For simplicity, in this example I will need to lag Var 1 and Var2, but not var 3.

    Do I need to make new lagged variables to run gllamm, and if so what's the easiest way to do that?
    Yes, if I recall well, gllamm (SSC) does not support time-series operators.

    Code:
    local vars "Var1 Var2"
    xtset Garden_ID_ Year
    foreach var in `vars'
    gen L`var'= L.`var'
    where LVar1 and LVar2 define the lagged variables.
    Last edited by Andrew Musau; 04 Aug 2018, 16:57.

    Comment


    • #3
      There is a loop in #2, so I am missing the brackets

      Code:
      local vars "Var1 Var2"
      xtset Garden_ID_ Year
      foreach var in `vars'{
           gen L`var'= L.`var'
      }

      Comment


      • #4
        Hi Andrew,

        Thanks so much! It appears to have worked. Question on the syntax: Stata recognizes "L." to mean lag?

        Comment


        • #5
          Yes, see the documentation on time series operators: https://www.stata.com/manuals13/tstsset.pdf

          Comment


          • #6
            Thank you Jorritt!

            Comment

            Working...
            X