Announcement

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

  • Growth Rates

    Hello!

    I am trying to calculate growth rates for income (both yearly and every 5 years), by district. The data is every 5 years, 2004, 2009, 2014 and I am struggling to generate these values. Apologies if it is very obvious, it has been a while since I used Stata.

    I have attached an image below of the data.

    Thank you!
    Attached Files

  • #2
    This is a cheat, but I'd construct a time variable that is just 1, 2, 3, and then xtset on that. Then you can just use lags.
    Code:
    egen time = group(t1)  //check to make sure you get the right result
    xtset time district
    bys district: g growth = ln(x)-ln(l.x)

    Comment


    • #3
      Thank you George.

      When implementing your code, I have the issue of district being a string variable. To tackle this I used the code:

      Code:
      encode district, gen(district1)
      drop district
      rename district1 district
      However once this is done and I re-run your code, I receive an error code saying the data is not sorted. Any ideas?

      Comment


      • #4
        Niall Beirne Make a unique ID for district too

        Code:
        egen id = group(district)
        
        cap which labmask
        
        if _rc {
            
            qui net inst gr0034.pkg
        }
        
        labmask id, values(district)
        ​​​​​​​

        Comment


        • #5
          xtset your data?

          bys district time: ...

          Comment


          • #6
            Thanks guys, all sorted!

            Comment


            • #7
              Jared Greathouse gave code which can be shortened to

              Code:
              egen id = group(district), label
              labmask from the Stata Journal has its uses, but it's not needed here.

              Further, the option delta(5) on your time variable can be applied with tsset or xtset.


              Comment

              Working...
              X