Announcement

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

  • Generating random variable from 95% confidence interval

    Hello,

    I would like to randomly generate a variable from the 95% confidence interval of a normally distributed variable. I've had no luck finding any suggestions so far. Any suggestions?

    Thanks in advance.
    Amit

  • #2
    I assume your 95% CI is stored in two local macros, lb and ub, containing the lower and upper limits respectively

    Code:
    local mean = 0.5*(`lb'+`ub')
    local sd = (`ub' - `mean')/invnorm(0.975)
    gen desired_random_variable = rnormal(`mean', `sd')

    Comment


    • #3
      Thanks you Clyde. I really have to brush up on my stats, but won't this just give me random values within the whole distribution, rather than from within the 95% CI?

      Comment


      • #4
        Your purpose isn't plain, but you're correct that Clyde's code will draw from the entire distribution (of estimates, not data values) implied. You can always ignore values you don't want using if.

        Comment


        • #5
          Confidence intervals are random, both in location and length. I can't see a rationale for generating observations "within" a confidence interval. Have you a reference?
          Last edited by Steve Samuels; 24 Dec 2015, 07:53.
          Steve Samuels
          Statistical Consulting
          [email protected]

          Stata 14.2

          Comment


          • #6
            Welcome to Statalist!

            I think what the discussion so far makes clear is that you have not succeeded in making your objective clear to those of us who have read your statement of the problem.

            At this point, we should ask that you please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post, looking especially at sections 9-12 on how to best pose your question. Also, if you give us more complete information about what you trying to accomplish with the random variable you wish to generate, we'll be able to better understand what you need and from that perhaps suggest an approach to accomplishing that with Stata. Sometimes the setting of the problem is important to helping communicate what is needed.

            Added in edit: Perhaps what you are looking for is to generate a random variable following the truncated normal distribution, as described in Wikipedia in the article on the truncated normal distribution. The formulae there, when translated to Stata using the normal() and invnormal() functions, would seem to offer an approach. But still, I'm hesitant to suggest that approach given my limited understanding of your objective.
            Last edited by William Lisowski; 24 Dec 2015, 12:55.

            Comment

            Working...
            X