Announcement

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

  • Lagged Values

    Hello. I am a total newbie with Stata. Almost zero, but even though i have to use this program for my thesis, meaning i have to master it before starting my project.
    The problem that i have is (if i can explain it properly in Stata key words):
    I have a set of 5000 companies. With different variables (for ex: Net Income, Equity, Assets and so on), i have put the data in panel form i think.
    At least it is divided by ID and Year. Meaning i have 5000 companies separated by ID, with variables between 2009 and 2013 ready to be used.
    When i try to do the lagged values i couldnt use this expression:
    "generate lagROE=lROE" and it gave me the error: "nothing found where name expected"

    So , i tried to do some more research on web about this issue before resorting for last measures and i managed to do this:
    "generate lROE=ROE[_n-1]" and it gave me the lagged values yes. The first year 2009 doesnt show because we dont have any value for 2008. the 2010 is 2009 , 2011 is 2012 is 2011 and so n.
    Thats correct FOR THE FIRST COMPANY. Then the lagged values for the next company of 2009 is the value of 2013 of the previous company.
    Do you see the error here? The next company, it should have no value for 2009 , and not being the 2013 value of the previous company.

    Important to say that i estimated ROE by myself doing generate ROE: NetIncome/Equity for ex

    Also the panel view was done doing:
    sort ID Year

    thank you very much.If you want i can attach the stata file.
    thank you again and very sorry for the dumb question.


  • #2
    try
    Code:
    generate lROE=ROE[_n-1] if ID==ID[_n-1]

    Comment


    • #3
      I'd get to grips with tsset. See the help for that command. You can use tsset to declare a panel dataset after which time series operators can be used as desired.

      Code:
       
      tsset id year 
      gen lROE = l.ROE
      What Ben suggests will be equivalent with a well-behaved dataset, but not otherwise. The more general point is twofold.

      1. Stata will do the right thing with panel data if it is told that you have panel data.

      2. Your code that worked didn't say anything about panel structure. Stata did what it was told to do.

      Comment


      • #4
        Thank you very much Nick. I just did that now and it worked fine. Sorry for the dumb question again.

        Comment

        Working...
        X