Announcement

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

  • #16
    Please read FAQ 12 and post all code and results between CODE delimiters, as described. In this case, show the results of bs4rw and a listing for three observations in "myresults.dta". Before first, a couple of improvements:

    1. set seed before you run bsweights.
    2. Run the code I showed in post #13 and show the results. You'll need these to compare any results from bs4rw.
    Steve Samuels
    Statistical Consulting
    [email protected]

    Stata 14.2

    Comment


    • #17
      bs4rw won't work for your problem, because tabulate, unlike svy: tabulate, leaves no results behind to use as expressions. But you can use svy: tabulate after bsweights, as the note at the start of the linked article makes clear. Here's a program that will save the replicate data sets. It uses a dataset with the replicate weights already created and copies code from Clyde's post #8 to get the prevalence rates. The logic of the program is to svyset with each replicate weight, one at a time, before running svy: tabulate.

      Code:
      /* Create empty dataset to hold results */
      clear
      save results, emptyok replace
      
      set linesize 90
      
      use http://www.stata-press.com/data/r14/nmihs_bs, clear
      drop bsrw11-bsrw1000  // keep 10 replicates for illustration
      
      /* Standard bootstrap analysis */
      svyset [pw = finwgt], vce(bootstrap) bsrweight(bsrw1-bsrw10)
      svy: tab agegrp childsex, row se
      
      tempfile t0
      keep agegrp childsex bsrw*
      save `t0', replace
      
      forvalues k = 1/10{
          use `t0', clear
          gen replicate = `k'
          qui svyset  [pw = bsrw`k']
          qui  svy: tab agegrp childsex
          forvalues i = 1/5 {
              gen  prev_`i' = _b[p`i'2]/(_b[p`i'2] + _b[p`i'1])
          }
          keep replicate prev_*
          append using  results
          qui save results , replace
          drop replicate
      }
       use results, clear
      
      . sum replicate prev_*
      
          Variable |        Obs        Mean    Std. Dev.       Min        Max
      -------------+---------------------------------------------------------
         replicate |     99,530         5.5    2.872296          1         10
            prev_1 |     99,530     .489717    .0254912   .4627656   .5300812
            prev_2 |     99,530    .4748849    .0101627    .458122   .4889681
            prev_3 |     99,530    .4964886    .0074928   .4828695   .5113196
            prev_4 |     99,530    .4529298    .0117695   .4413744   .4756126
      -------------+---------------------------------------------------------
            prev_5 |     99,530    .4691171    .0195567   .4409228   .4975689
      .
      Last edited by Steve Samuels; 31 Dec 2015, 14:19.
      Steve Samuels
      Statistical Consulting
      [email protected]

      Stata 14.2

      Comment


      • #18
        You can't use tabulate with bs4rw, but you can use proportion, because it does return estimates. This leads to a much simpler program. Continuing the example above:

        Code:
        use http://www.stata-press.com/data/r14/nmihs_bs, cleardrop bsrw11-bsrw1000
        #delim ;
        bs4rw
         prev_1 = _b[_prop_2:_subpop_1]
         prev_2 = _b[_prop_2:_subpop_2]
         prev_3 = _b[_prop_2:_subpop_3]
         prev_4 = _b[_prop_2:_subpop_4]
         prev_5 = _b[_prop_2:_subpop_5],
         rweights(bsrw*) saving(dresults, replace):
         prop childsex [pw = finwgt], over(agegrp);
        
        #delim cr
        use dresults, clear
        sum
        with results
        Code:
        . bs4rw
        >  prev_1 = _b[_prop_2:_subpop_1]
        >  prev_2 = _b[_prop_2:_subpop_2]
        >  prev_3 = _b[_prop_2:_subpop_3]
        >  prev_4 = _b[_prop_2:_subpop_4]
        >  prev_5 = _b[_prop_2:_subpop_5],
        >  rweights(bsrw*) saving(dresults, replace):
        >  prop childsex [pw = finwgt], over(agegrp);
        
        BS4Rweights results                             Number of obs     =      9,953
                                                        Replications      =         10
        
              command:  proportion childsex [pweight= finwgt], over(agegrp)
               prev_1:  _b[_prop_2:_subpop_1]
               prev_2:  _b[_prop_2:_subpop_2]
               prev_3:  _b[_prop_2:_subpop_3]
               prev_4:  _b[_prop_2:_subpop_4]
               prev_5:  _b[_prop_2:_subpop_5]
        
        ------------------------------------------------------------------------------
                     |   Observed   Bootstrap                         Normal-based
                     |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              prev_1 |   .4798133     .02687    17.86   0.000     .4271491    .5324774
              prev_2 |   .4852007   .0107124    45.29   0.000     .4642048    .5061966
              prev_3 |   .4915641   .0078981    62.24   0.000     .4760841    .5070441
              prev_4 |   .4551095   .0124061    36.68   0.000      .430794     .479425
              prev_5 |   .4686168   .0206145    22.73   0.000      .428213    .5090205
        ------------------------------------------------------------------------------
        .
        . use dresults, clear
        (bs4rw: proportion)
        
        . sum
            Variable |        Obs        Mean    Std. Dev.       Min        Max
        -------------+---------------------------------------------------------
              prev_1 |         10     .489717      .02687   .4627656   .5300812
              prev_2 |         10    .4748849    .0107124    .458122   .4889681
              prev_3 |         10    .4964886    .0078981   .4828695   .5113196
              prev_4 |         10    .4529298    .0124061   .4413744   .4756126
              prev_5 |         10    .4691171    .0206145   .4409228   .4975689
        .
        Note that you can discover the names of scalars for any estimation commnd by adding the option "coeflegend" , e.g.

        Code:
        proportion childsex [pweight= finwgt], over(agegrp), coeflegend
        Try it!


        Last edited by Steve Samuels; 31 Dec 2015, 19:12.
        Steve Samuels
        Statistical Consulting
        [email protected]

        Stata 14.2

        Comment


        • #19
          Corrections: the command to show parameter names had an extra comma. It should be:
          Code:
          proportion childsex [pweight= finwgt], over(agegrp) coeflegend
          The very first line in the first code block jumbled two commands together. The correct version is:
          Code:
          use http://www.stata-press.com/data/r14/nmihs_bs, clear
          drop bsrw11-bsrw1000 // keep 10 replicates for illustration
          Steve Samuels
          Statistical Consulting
          [email protected]

          Stata 14.2

          Comment

          Working...
          X