Announcement

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

  • Using sample weights

    Hello,
    I am reaching out to check if I have used sample weights correctly. I am calculating the percentage of households with food-insecure children in each state and year and then collapsing the percentages to generate a state-level variable. Do I also need to use sample weights in the initial steps (codes are below) when calculating my numerator and denominator for percentages? I tried to do it, but Stata wouldn't allow me to use sample weights with counts (unless I used it incorrectly).

    bysort year statefip: egen insec_num = count (hh_child_insec) if hh_child_insec ==1
    bysort year statefip: egen insec_denom = count (hh_child_insec) if hh_child_insec !=.
    bysort year statefip: gen insec_per = (insec_num / insec_denom) * 100 if insec_denom > 0

    collapse (mean) state_food_insec = insec_per [aweight=fshwtscale], by (year statefip)

    Thanks,
    Arun

  • #2
    I forgot to mention that fshwtscale is a household-level weight. I am unsure if I am using it correctly.

    Comment


    • #3
      It looks like your first two steps create a numerator equal to the number of households (assuming that's the unit of observation here) with food insecurity and a denominator of all households that are not missing a value for the insecurity variable. The third line then calculates the state-year level percentage without weights, which I don't think you want. Also note that missing values are treated as infinity so when you use if insec_denom > 0, that will include all with missing values for insec_denom if there are any.

      Your collapse command then collapses the unweighted state-year level percentage that, presumably, has the same value in every row with the same state and year and uses analytical weights to weight each row. My guess is that if this command would run, it would produce the same state-year level percentage you already calculated since it should be averaging the same number within each state-year; the weights shouldn't even matter here.

      Without seeing the error message, I'm not sure why you could not collapse this data. However, I don't think this code is doing what you want. It sounds like all you need is to use collapse by year and statefip to generate the mean percent of insecure households weighted by fshwtscale, which is likely not an analytical weight. I suggest reading the help files on weight to determine what type of weight you have first, then using a single collapse command to generate your state-year level means.

      Comment


      • #4
        Thanks for the suggestions, Craig. I was able to collapse the state percentages, but I wasn't sure I used the weights correctly. fshwtscale is analytical weights for households (Data source: "This weight should be used when analyzing the food security scale data"). I could not determine how to use the weights when calculating state-level percentages in the third line. I wanted to use a single collapse command but couldn't figure out the way to do it.

        Comment


        • #5
          Assuming hh_child_insec is a dummy variable equal to one when the household contains a child and is "food insecure" and that your weights are analytic weights, you only need a single line of code

          Code:
          collapse state_food_insec = hh_child_insec [aweight=fshwtscale], by(year statefip)
          The mean of a dummy variable will be the percent of observations that have the variable equal to 1. Also, (mean) is the default so it's not necessary to write it if you don't want to.

          If this is CPS data obtained from IPUMS, you may want to refer to the documentation. According to the variable's description, it has 4 "implied decimal places". I don't have the data to look at but it sounds to be that you may have to divide the variable by 10,000. It's also not clear to me what type of weight this variable is. The documentation is not clear for this particular variable. I would suggest finding the documentation on the CPS website directly to figure that out. The quote you provide does not mean they are analytic weights.

          Comment


          • #6
            Craig Kerr, many thanks for helping out. Yes, it is IPUMS CPS data. I will spend more time digging into weights in the IPUMS documentation.

            Comment

            Working...
            X