Announcement

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

  • Create change variable for timeseries data.

    Hi,
    my problem is twofold. I downloaded a database containing gvkey, sic code, year (1995 - 2005), year-end date, and 13 variables, for about 3000 US companies. This information is organized in columns, with the first company taking the first 11 rows (years), directly followed by the next company. I have to create new variables that represent year-to-year change. I was unable to find the syntax for this command, although I assume this to be quite straightforward (like in Excel). The second problem is the necessary leap from one company to the next. How do I tell STATA to end the subtraction at the end of a certain company (year 2005), to continue with the next. Is this even possible?

  • #2
    not clear what your variable names are for which you want the change, but here is an example (you will need to change the variable name), assuming that gvkey is the company id
    Code:
    sort gvkey year
    gen change1=var1-var1[_n-1] if gvkey==gvkey[_n-1]

    Comment


    • #3
      Thx Rich. Your example was certainly helpful. However, applying by gvkey instead of the if condition will do the job perfectly.

      Comment


      • #4
        yes; one of the things I particularly like about Stata is that, esp. for data issues, there are usually many ways to get to the desired result

        Comment

        Working...
        X