Announcement

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

  • How to draw a lognormally distributed variable with a certain median and certain quartiles?

    Dear forum,
    I would like to create a sample where N=2000 and, for each simulated subject, to draw a lognormally distributed exposure variable X with a median of 1 and first and third quartiles of 0.5 and 2. Then, I would like to create an outcome variable Y conditional on the lognormal exposure, so that the coefficient for X after a linear regression with X and Y equals 1.2. Does anyone know how to do this in Stata 15?


    Best regards,
    Kjell Weyde

  • #2
    To get lognormal random deviates, I get normal random deviates and exponentiate. In a lognormal median and geometric mean coincide: you want 1 and that is exp(0) so the default of a normal having mean 0 is what you want. So all the focus is on getting the variability right. You want the upper quartile to be 2 so you need a factor converting from a standard normal to that scale.

    Note that ln(2)/invnormal(0.75) is a constant and as such better pre-calculated, not as in my lazy code below.

    Code:
    . clear
    
    . set seed 2803
    
    . set obs 10000
    number of observations (_N) was 0, now 10,000
    
    . gen wanted = exp(rnormal(0, ln(2)/invnormal(0.75)))
    
    . su wanted, d
    
                               wanted
    -------------------------------------------------------------
          Percentiles      Smallest
     1%     .0972269       .0167617
     5%     .1881426       .0221405
    10%     .2708793       .0264062       Obs              10,000
    25%      .510858       .0331743       Sum of Wgt.      10,000
    
    50%     1.025915                      Mean           1.726721
                            Largest       Std. Dev.      2.323413
    75%     2.040952       28.95724
    90%     3.790504       29.82361       Variance       5.398248
    95%     5.494809       34.42119       Skewness       5.563267
    99%     11.11678        56.4502       Kurtosis       65.02357
    
    . gen wanted2 = exp(rnormal(0, ln(2)/invnormal(0.75)))
    
    . tabstat wanted* , s(p25 median p75)
    
       stats |    wanted   wanted2
    ---------+--------------------
         p25 |   .510858  .4992978
         p50 |  1.025915  .9883743
         p75 |  2.040952  1.999719
    ------------------------------

    Comment


    • #3
      Is there a way to draw a lognormally distributed variable if I only know the min and the max value?

      Context: I am trying to estimate the impact of an intervention on income which can be from $1000 to $30000. I want to assume a lognormal distribution to calculate the mean impact.

      Comment


      • #4
        The empirical minimum and maximum hardly fix even those distributions. bounded on both sides, so you need white magic and rare luck. The geometric mean of the extremes could be an estimator of the geometric mean, which viscerally I imagine to be less lousy than using their mean to estimate the mean.

        Comment


        • #5
          Hi Nick,

          Is this something that would be possible if you had confidence interval information -- 95% & 90% CI's for the lognormal distribution and wanted to run a monte carlo simulation to estimate the mean of the lognormal?

          Thanks

          Comment


          • #6
            95% & 90% CI's for what parameter of the lognormal distribution?
            I can only make sense of this as saying that you have an estimate of the mean through a confidence interval. I suppose it's possible that someone cites only the limits, but then I would expect the mean to be recoverable as the geometric mean of the limits.

            But there's more than one way to get those limits, so I don't and can't know your exact situation,

            Comment


            • #7
              Yes, I was thinking of estimating the mean of a lognormal distribution using information about the confidence interval for the mean. Thanks!

              Comment

              Working...
              X