Announcement

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

  • Solution: lnskew0 back-transformation

    I appreciated the flexibility and 1-line simplicity of lnskew0 to transform any given variable(s) into a normal distribution, however I struggled to back-transform the resulting values into their original form.

    Forward transformation: transformedX = ln(S * originalX - K), where S is +1 or -1, and K is a positive or negative continuous number

    Backward transformation: originalX = (exp(transformedX) + K) / S, wherein the value of K is stored and recovered from r(gamma) but the value of S is mysteriously not stored

    While it would be nice to have r(sign) stored in a future version of lnskew0 (I believe originally written by [email protected]), I found - luckily - that the sign happens to be indicated in the transformed variable's label (!!) so it can be recovered as follows:

    Code:
    lnskew0 ln_value = value
    scalar k = r(gamma)
    local lbl : variable label ln_value
    scalar sign = cond(substr("`lbl'", 4, 1)=="-",-1,+1)
    gen value = (exp(ln_value) + k) / sign
    I hope this helps someone...
    Last edited by Jonathan Afilalo; 01 Jul 2025, 08:11.
Working...
X