Announcement

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

  • How do I insert two weights in one tabulate command?

    Hi Statalist,

    I have a survey with two sample populations. One is representative of the general population (frequency 2029), one is representative of a specific target population (frequency 5934). I have to create very simple tabulations of variables that capture questions asked of BOTH the general and target populations. However, I have never done such tabulations including two different weights. Any advice on how I can integrate two different weights into one tabulate command?


    Code:
    . tab sample
    
    Data Only Variable: |
                 Sample |      Freq.     Percent        Cum.
    --------------------+-----------------------------------
                General Pop |      2,029       25.48       25.48
    Target Pop |      5,934       74.52      100.00
    --------------------+-----------------------------------
                  Total |      7,963      100.00
    Naturally, each sample population comes with its own weights, namely 'weight_gp' for the general population, and 'weight_target' for the target population

    Code:
    . codebook weight_gp // for general pop analyses
    
    ---------------------------------------------------------------------------------------------
    weight_gp                                    Post-Stratification weight for Gen Pop (n=2,029)
    ---------------------------------------------------------------------------------------------
    
                      type:  numeric (double)
    
                     range:  [.212,3.052]                 units:  .0001
             unique values:  1,129                    missing .:  5,934/7,963
    
                      mean:         1
                  std. dev:   .328805
    
               percentiles:        10%       25%       50%       75%       90%
                                 .6517     .7857     .9459    1.1671    1.4248
    
    
    . codebook weight_target // for target pop analyses
    
    ---------------------------------------------------------------------------------------------
    weight_target              Post-Stratification weight for Qualified Targeted Sample (n=5,934)
    ---------------------------------------------------------------------------------------------
    
                      type:  numeric (double)
    
                     range:  [.0655,7.6575]               units:  .0001
             unique values:  1,647                    missing .:  2,029/7,963
    
                      mean:         1
                  std. dev:   1.27466
    
               percentiles:        10%       25%       50%       75%       90%
                                 .1665      .293     .5625    1.1167    2.1893
    I am now looking at a survey question that was asked of both the general and target populations. The question is captured in the variable 'mleave_pew'. codebook & dataex:

    Code:
    mleave_pew   Following the birth or adoption of a child, do you think MOTHERS should be able 
    ---------------------------------------------------------------------------------------------
    
                      type:  numeric (byte)
                     label:  Q14A
    
                     range:  [1,99]                       units:  1
             unique values:  3                        missing .:  0/7,963
    
                tabulation:  Freq.   Numeric  Label
                             7,802         1  Yes, mothers should be able to
                                              take leave
                               115         2  No, mothers should not be able
                                              to take leave
                                46        99  Refused
    
    
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte mleave_pew
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    2
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    end
    label values mleave_pew Q14A
    label def Q14A 1 "Yes, mothers should be able to take leave", modify
    label def Q14A 2 "No, mothers should not be able to take leave", modify
    Again my question is, how can I create a simple weighted table using both weights?

  • #2
    Hi Rosa
    I think you could "combine" both weights by creating a new variable:
    Code:
    gen double comb_weight=weight1 if q14a==1
    replace comb_weight=weight2 if q14a==2

    Comment


    • #3
      I don't know why I didn't think of that myself. Of course that should work. Best of thanks Fernando.

      Comment


      • #4

        Code:
        gen double comb_weight= weight1 * (q14a==1) + weight2 * (q14a == 2)
        is another way to do it.

        Comment

        Working...
        X