Announcement

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

  • Why do I get no observations if I use the svy command?

    I have four variables: town, weights, survey_wave, and pizza (preference for pizza on a 1-5 scale). The data is on the individual-level. My code is:

    Code:
    svyset town [pweight=weights]
    tab pizza if survey_wave==1
    svy: tab pizza if survey_wave==1
    The odd thing is that when I run the tab with -svy-, I get no observations. I have no idea why. There are weights for both survey waves. I tried to create a -dataex- sample, but no matter what I did, it only included entries from wave==2, not wave==1.

    Goes without saying, but obviously the above example is fake.

  • #2
    You should be able to get an extract with

    keep if survey_wave==1
    dataex ...

    I would check what the weights are when survey_wave == 1
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 18.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      I am also facing this issue. Did you ever resolve it?

      Comment


      • #4
        As with the O.P. of #1, nobody can give you a firm answer without seeing the exact code used and an example of the data that reproduces the problem with that code. Nevertheless, the most likely explanation is that in the observations that satisfy the -if- condition the values of the pweight variable either missing or zero.

        That said, even if all the weights were present and non-zero, the correct way to do that tabulation is -svy, subpop(if survey_wave == 1): tab pizza-, not to use an -if- condition on -tab-. Had O.P. gotten results from that code they would likely have been incorrect anyway because of that error.

        Comment


        • #5
          Dear Stata listers,
          I am facing a similar problem of no observations with survey weights.

          Let me show the summary of the variable without the weights first:

          . sum v133

          Variable Obs Mean Std. Dev. Min Max

          v133 124,385 6.115086 5.270271 0 99
          Here is the code and the result of the weight variable

          gen wgt = v005/1000000

          . sum wgt

          Variable Obs Mean Std. Dev. Min Max

          wgt 124,385 1 .846759 .019386 3.443244
          Here is the code and the result of setting weight:

          . svyset [pw=wgt], psu(v021) strata(v022)

          pweight: wgt
          VCE: linearized
          Single unit: missing
          Strata 1: v022
          SU 1: v021
          FPC 1: <zero>
          Here is the code and error in the output:

          . svy: mean v133
          (running mean on estimation sample)
          no observations
          r(2000);
          Can you please figure out the error in this?

          Comment


          • #6
            Perhaps the problem is missing values of the psu (v021) or strata (v022) variables. What do you get with:
            Code:
            summ v021 v022 if !missing(wgt, v133)
            If this does not reveal the source of the problem, then I think that to get further advice you would need to post example data. Be sure to use -dataex- to do that. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

            When asking for help with code, always show example data. When showing example data, always use -dataex-.

            Comment


            • #7
              Thank you Clyde.
              Yes, you were absolutely right. v021 has no observations.

              . summ v021 v022 if !missing(wgt, v133)

              Variable Obs Mean Std. Dev. Min Max

              v021 0
              v022 124,385 37.60576 21.21877 1 73
              The problem is resolved now.


              Comment

              Working...
              X