Announcement

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

  • How do I write log(First Diff(Variable) in STATA

    How do I write log(First Diff(Variable) in STATA.

  • #2
    Assuming that your data set is properly tsset or xtset:
    Code:
    gen newvar = log(D.oldvar)
    https://www.kripfganz.de/stata/

    Comment


    • #3
      Sebastian is right, but I can't see that this construct is of any use unless your variable is always increasing, as with just one interval in which the difference was zero or negative there would be a missing value returned. Perhaps you know that condition is satisfied for the data.

      Comment


      • #4
        Nick makes a very good point. It is indeed often desired to compute so-called "log-differences". This is not the same as the log of the differences but would rather be the difference of the logs, which approximately equals the growth rate of a variable:
        Code:
        gen newvar1 = log(oldvar)
        gen newvar2 = D.newvar1
        https://www.kripfganz.de/stata/

        Comment

        Working...
        X