Announcement

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

  • Putexcel in Survey data

    Y'all,
    I am using Stata 13.1 on windows 7. I am trying to export my Stata output, including my confidence intervals to an excel file.

    I use this code for the whole population, and it works:

    estpost svy: tabulate diabetes , percent ci // diabetes prevalence
    mat pct = e(b)'
    mat lb = e(lb)'
    mat up = e(ub)'

    putexcel A3=("Non diabetes") A4=("diabetes") B3=matrix(pct) C2= ("Lower CI") c3=matrix(lb) D2=("Upper CI") d3=matrix(up) using test, replace

    But when I try to specify my analysis to one age group by the following code I get this error: confidence interval cannot be estimated "stratum with single sampling unit."


    estpost svy: tabulate diabetes if age==1 , percent ci // diabetes prevalence
    mat pct = e(b)'
    mat lb = e(lb)'
    mat up = e(ub)'

    putexcel A3=("Non diabetes") A4=("diabetes") B3=matrix(pct) C2= ("Lower CI") c3=matrix(lb) D2=("Upper CI") d3=matrix(up) using test, replace

    I tried to use preserve keep age==1 and then restore commands, but it did not work.

    Thank you guys in advance.

  • #2
    What you're trying to do cannot be done. It is a mathematical requirement of the survey covariance matrix estimator (from which the CIs are calculated) that every stratum contain more than one sampling unit. When you imposed the restriction -if age == 1-, you stumbled because, apparently there is some stratum in your data that has only one sampling unit that also has age == 1.

    A partial solution to this problem is to identify the offending stratum (or strata). Running -svydes if age == 1- will give you this information. Then you could recode the strata so as to combine each offending stratum with some other stratum that is otherwise similar to it. Of course, this doesn't really give you exactly what you were hoping for, but it is the closest you can come to it.

    By the way, though it is not the cause of your error message, I should point out that both -if age == 1- and -preserve- followed by -keep if age == 1- would get you incorrect results if it did run. The correct way to do this is -svy, subpop(if age == 1): tabulate diabetes, percent ci-.

    Comment


    • #3
      Thank you for your response.

      I have tried this command:

      svy: proportion diabetes, over (age)

      It gives me 95% CI but I cannot find a way to export 95% CI into excel with putexcel command.

      Comment


      • #4
        -svy: proportion- leaves these results in the matrix r(table). You can make it a "real" matrix with -matrix M = r(table)- immediately after -svy: proportion- runs. Then you can apply -putexcel- either to the entire matrix M, if you like, or you can use -putexcel- with the specific elements of M that you want.

        Comment


        • #5
          Thnx a lot

          Comment

          Working...
          X