Announcement

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

  • Missing values generated after trying to generate ln function



    Before trying to generate my variable I had this variable.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double rea
      39.13813266666667
     60.410011999999995
      51.08060033333334
              62.466026
      58.54461133333333
     40.808108000000004
      20.17195633333333
     12.483683466666667
     -.2111375666666667
      .5451751000000004
     -37.34087466666667
     -23.72058266666667
    -13.459465066666667
    -12.350081633333332
    -33.336627666666665
     -27.24211366666667
             -23.977575
             -18.353044
             -27.757518
     -20.14504066666667
             -25.616022
    -26.788110666666668
             -52.681589
     -36.48232166666667
     -48.39284266666667
     -65.86139466666667
     -71.29853133333333
             -53.494223
    -41.291238666666665
             -25.291703
             -25.120687
    -11.800554066666665
     11.860477533333333
     3.7127351333333336
     -8.790290666666666
      5.500527566666666
               15.59104
     13.602316466666666
     2.1667307900000004
     14.136153666666667
     13.700408666666668
     -6.543706466666666
    -20.250679666666667
     -8.576893003333334
      9.022044406666666
     13.382336333333333
      5.221383433333333
              8.4833935
             -9.1815819
    -19.907728666666667
     -32.55594233333333
    -20.428037666666665
     -8.793030700000001
     4.2965170666666666
     -6.222860533333333
    -13.556194533333333
    -23.626597333333333
            -8.37051217
    -1.6039786999999996
     23.068966333333332
     31.917483333333337
      36.41205033333333
     29.452066666666667
      9.859649666666668
    -3.9989844666666663
     -9.716630499999999
     -34.44321300000001
    -12.624126133333334
             -4.8125161
    -15.160078333333333
             -15.143239
    -18.731099999999998
     -35.81994366666667
     -46.57734100000001
              -59.66092
     -49.17695533333333
     -56.07041733333333
    -42.895834666666666
     -36.91814933333333
             -13.267707
     -5.286501533333333
      4.948936066666667
      6.775513666666666
      8.435973533333334
     -2.792858986666667
             -9.4281721
     -40.64816866666667
    -57.250793666666674
     -45.27946333333333
    -40.545537333333336
     -38.74795833333334
             -4.0900479
             10.6210139
      32.22018033333333
      39.52709866666667
     102.57146666666665
              121.67917
              83.438888
              94.319298
     117.48598333333335
    end
    I wanted to type in these codes but I keep getting 86 missing values. How do I solve this issue please?

    gen lread=ln(rea)
    gen lrea_1=l.lrea
    gen Dlrea=d.lrea
    lab var lrea "ln(rea)"

  • #2
    Your variable has negative values; the logarithm is not defined for negative values. There is nothing to "solve". Why do you want to transform your variable in this way?

    Best
    Daniel

    Comment


    • #3
      Cross posted with Daniel
      Hi Shazzle
      Unfortunately that is an issue that CANT be solved. The log function is undefined over negative values or zero.
      Im guessing you want to use the log transformation to obtain some measure of growth, however, growth is undefined when it goes from a negative number to a positive one. so perhaps a different transformation will be needed.
      HTH
      Fernando

      Comment


      • #4
        Hi,

        This is because I wanted to interpret it as a %change rather than in levels.

        Comment


        • #5
          The logarithm of a negative number is defined: it has complex value. But that wouldn’t be useful statistically.

          Comment


          • #6
            Thank you Nick!

            Comment


            • #7
              Originally posted by Shazzle Singh View Post
              This is because I wanted to interpret it as a %change rather than in levels.
              You could probably estimate your model, then use margins to estimate (semi-)elasticities. See

              Code:
              help margins
              When you are not comfortable with the linearity assumption, perhaps consider a generalized linear model. See

              Code:
              help glm
              Best
              Daniel

              Comment


              • #8
                Thanks Daniel!

                Comment

                Working...
                X