Announcement

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

  • Creating a change variable

    Hey guys,

    I'm trying to add change variables but it doesn't really work. For the variable coc I need the percentage change (year-(year-1)/(year-1)*100), and for the variables irq, at, beta, lev and bm I need the absolute change (year-(year-1)). Note that every firm (firm id) has its own time series.
    Does anybody know the easiest way to create these variables? Showed below are the first rows of my data-set.

    Any help would be appreciated. Thanks!
    firm id year coc irq at beta lev bm csr
    1 2011 - 0 - - - - 0
    1 2012 - 0 3618.793 - 0.405952 - 0
    1 2013 - 0 6613.581 - 0.314353 0.216467887 0
    1 2014 0.2352727 5.21 11573.5 1.04333 0.376943 0.514705297 0
    1 2015 0.097794 26.8 14155.22 1.88716 0.332634 1.206526532 0
    3 2010 - 86.67 4946.5 - 0.162438 0.442065995 0
    3 2011 0.1431113 85.08 5323.9 - 0.143072 0.436034294 1
    3 2012 0.1606975 88.63 5627.1 - 0.13993 0.449940363 1
    3 2013 0.1445998 86.61 5736 - 0.15713 0.365684741 1
    3 2014 0.100875 89.72 6325.5 - 0.169915 0.441926384 1
    3 2015 0.1558223 85.14 5932.2 - 0.187839 0.584596788 1

  • #2
    After In posted this, I kept trying to find the right command.

    I tried to create a lag variable for all the variables, so I can subsequently create the change variable.

    I tried to do this with the following command:



    xtset firmid year
    gen laggedcoc = L1.coc
    gen laggedirq = L1.irq
    gen laggedsize = L1.size
    gen laggedlev = L1.lev
    gen laggedbeta = L1.beta
    gen laggedbm = L1.bm

    This only worked for the variable irq because this variables has no missing values.
    For the other variables the command didn't create any lag variables. Why does it not create the lag variables for the values that are not missing? What changes do I have to make in the command to get all the lag variables?

    Thanks in advance.

    Comment


    • #3
      Welcome to Statalist.

      Based on what you've shown us of your data, the variables other than irq seem to have "-" indicating a missing value. Since Stata represents missing values for numeric variables using a single period character, or a period followed by a lower-case letter, this suggests the data were imported into Stata as string variables rather than as numeric variables.

      First use
      Code:
      describe
      to confirm this, and then use commands like the following to convert your string variables to numeric.
      Code:
      destring coc, force replace
      You should review the output of help describe and especially help destring to understand what these commands do.

      Once you successfully convert your data to numeric, commands like the following should do what you seek.
      Code:
      xtset firmid year
      generate coc_pctchg = 100*(coc-L1.coc)/L1.coc
      generate irq_chg = irq-L1.irq
      or perhaps
      Code:
      xtset firmid year
      generate coc_pctchg = 100*(D1.coc)/L1.coc
      generate irq_chg = D1.irq
      For this, help tsvarlist provides useful guidance.

      Comment


      • #4
        Hi William,

        Thank you so much for your help.

        I indeed copied the data from excel into stata, and therefore a wrong indicator for a missing value was present.

        After converting my data into numeric, the first command did exactly what I was looking for, thanks again!!

        Comment

        Working...
        X