Announcement

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

  • Capturing confidence intervals in newly generated variables

    Hi,

    I'm using the following code to determine the 95%CI of a proportion:

    cii means n_sample n_cases, poisson
    I would like to capture both the upper and lower CI's in newly generated variables, but I can't see an option to do this using cii. Is there a simple way to do this?

    Thanks,

    Alex

  • #2
    I've captured the proportion already by simply running:

    foreach var of varlist a b c d e f {
    gen rate_`var' = `var'/followup
    replace rate_`var'=round(rate_`var', 0.01)
    }

    Really what I want is three new variables: the lower CI, the proportion, and the upper CI.

    Comment


    • #3
      Are you really using
      Code:
      cii means n_sample n_cases, poisson
      I ask because if n_sample and n_cases are variable names this will just give you an error message. -cii- expects numbers, not variable names. If n_sample n_cases are scalars, then that works. Or maybe you just meant to show a placeholder for some numbers you are using.

      Anyway, assuming you are really using cii and have scalars or literal numbers in the right places, you can find the proportion along with the upper and lower confidence limits in r(mean), r(lb) and r(ub), respectively. So you can just run
      Code:
      gen proportion = r(mean)
      gen lower_bound = r(lb)
      gen upper_bound = r(ub)
      That said, there aren't a lot of situations in Stata where it makes sense to create a whole variable just to capture one number. If this isn't one of those situations, think about saving this results in scalars or local macros instead.

      Comment

      Working...
      X