Announcement

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

  • Exponent operator doesn't work with generate

    Can anyone explain this problem I'm having in Stata 15.

    I just want to generate a variable which is an existing variable raised to a power. ^ operator doesn't seem to work with generate, even though it works fine with individual values in my data.
    Click image for larger version

Name:	Screenshot 2020-04-16 10.56.50.png
Views:	1
Size:	13.7 KB
ID:	1547223



    Thanks,
    Garrett

  • #2
    The power operator invokes code that uses logarithms, which falls over when there are zero or negative arguments.

    The fact that display gives you an answer here arises because the problem is then split into powering 253.6012 and then (and only then) negating the result. That follows from precedence rules.


    You need, I presume,

    Code:
    gen quotient_exp = sign(quotient) * abs(quotient)^1.32 
    The problem was discussed in

    https://blog.stata.com/2011/01/20/ho...ulates-powers/

    https://www.stata-journal.com/sjpdf....iclenum=st0223

    Comment


    • #3
      Perfect.
      Thanks Nick

      Comment

      Working...
      X