Announcement

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

  • Does Stata store the results of the se option for the command svy: tabulate and if so how can I access them?

    Good Afternoon,

    I am able to use the following commands to automate the reporting of summary statistics for a complex survey analysis that I am running:

    Code:
    svy: tabulate myvar, se
    matrix z = e(b)'
    local a = round(z[1,1] * 100, 0.1)
    putexcel C1("Percent of MyVar") C2("`a'%")

    What I'm wondering is does Stata store the results of the svy: tabulate command's se option somewhere so that I can access these and plug them in a similar fashion. For example:

    Code:
    svy: tabulate myvar, se
    matrix z = e(Standard Error)
    local a = round(z[1,1], 0.01);
    putexcel D1("Standard Error") D2("(`a')")

    OS: Windows 7 Professional, SP1
    Software: Stata 13.1

    I apologize if is this is a basic question. I have tried to find the answer via the great Google machine, documentation, and the Statalist forum search engine but have been unable to.


    Thank you for your assistance,

    Joshua Goetz

  • #2
    Your first block of code would have displayed only one proportion. Here's something that might work. I'll leave the putexcel command to you.

    Code:
    sysuse auto, clear
    svyset _n
    
    svy: tabulate rep78, se
    matrix z = e(b)'
    matrix v = e(V)
    local rows = rowsof(z)
    
    forvalues i = 1/`rows'{
        local a`i' = round(z[`i',1] * 100, 0.1)
        local se`i' = round(sqrt(v[`i',`i'])*100, 0.1)
        di `i'  " " `a`i'' " " `se`i''
    }
    Steve Samuels
    Statistical Consulting
    [email protected]

    Stata 14.2

    Comment


    • #3
      I'd prefer to use Roger Newson's parmest package (SSC), which will put all results into a data set. Then you can use a simple export excel statement. To make sure that all CIs are in the (0,1) interval, svy tab computes CIs by estimating standard errors for the logits of the proportions, then transforms CIs for the logits to CIs for the proportions. parmest doesn't "know" to do this, so you must recompute the CIs by hand.
      Code:
      sysuse auto, clear
      svyset _n
      
      svy: tabulate rep78,  ci se
      /* parmest will replace data, so save or preserve if necessary */
      parmest,  norestore
      list  /* Note negative confidence limits */
      gen rep78=_n
      rename estimate prop
      
      /* Get CI for logits, then transform */
      tempvar logit selogit bound
      gen  `logit' = logit(prop)
      gen  `selogit' = stderr/(prop*(1-prop))  // SE of  of logit
      gen  `bound' = invttail(dof,.025)*`selogit'
      
      gen llim = invlogit(`logit'-`bound')
      gen ulim = invlogit(`logit'+`bound')
      format prop stderr llim ulim %6.3f
      foreach v of varlist prop stderr llim ulim {
          replace `v' = round(100*`v',.1)
      }
      
      list rep78 prop stderr llim ulim
      label var rep78 "78 Repair Score"
      label var prop "Percent"
      label var stderr "Std Error"
      label var llim "Lower 95 CL"
      label var ulim "Upper 95 CL"
      
      export excel rep78 prop stderr llim ulim using results01, ///
      firstrow(varlabels) replace
      Last edited by Steve Samuels; 03 Aug 2015, 09:14.
      Steve Samuels
      Statistical Consulting
      [email protected]

      Stata 14.2

      Comment


      • #4
        Thank you very much for you help and the information about computing the confidence intervals for svy: tabulate. The program I'm writing updates a regular report that has a very precise format so I am using putexcel to update individual cells across a variety of worksheets.

        Your code has been invaluable in helping me to resolve the issue I was facing.

        Sincerely,

        Joshua Goetz

        Comment


        • #5
          Joshua Goetz,
          Would you mind sharing the code you ended up using including the putexcel piece. I'm fairly new to STATA and don't have a programming background and it sounds like I'm trying to something similar. Basically I want to export the observations, percent, CI's, CV and counts into a serious of static tables that are updated with each new iteration of the survey.

          The data is bootstrapped and I can't figure out how to export using putexcel the CI's and CV values. The CV is used to determine what data we can release.

          *overall general health
          svy, subpop(peel):tab genhealth, per cv ci obs,
          svy, subpop(peel):tab genhealth, count format(%11.0fc)

          *general health by income categories
          svy, subpop(peel): tab genhealth income2, per col cv ci obs
          svy, subpop(peel): tab genhealth income2, count format(%11.0fc)

          I've searched high and low and cannot figure out how to do this. Likely from my limited understanding of STATA and programming language in general.

          Many thanks,
          Suzanne

          Comment


          • #6
            hello,

            svy:tab ma_grp pandemic3 if bf10==1, obs row percent ci format(%9.2fc)
            gives me the following result,
            Click image for larger version

Name:	Screenshot 2023-05-25 at 2.45.48 PM.png
Views:	1
Size:	277.6 KB
ID:	1714988




            I want to have a column that will show the difference between Row% i.e
            0<bf10
            Mother’s age pre [95% CI] post [95% CI] Pp [95% CI]
            <20 year 86.91 13.09 -73.82

            can anyone help?

            Comment

            Working...
            X