Announcement

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

  • Error while using probability weights, -xtreg- across multiple surveys

    Hello everyone,

    I have individual level data on health outcomes collected by different surveys in a country. I want to test the impact of a specific policy that was rolled out at the regional level with said rollout differeing over the years by regions.

    Although the surveys are modeled like each other only two of the survey waves are administered by the same entity while the third was administered by another organization. Regardless, survey questions, responses were all recorded exactly the same.

    I appended the surveys to have repeated cross-sectional data at the individual and xtset at the regional level to capture the time change of regional policy rollout i.e. rollout changes by region and year

    I realize that there would be concerns about sampling, so I constructed population weights i.e. known percentage of regional population/sample percentage of the population at the district by the wave.

    However when I run my regression, I get the error,

    weight must be constant within wave

    which for a district, within the wave, is constant.

    Hereunder is my code:

    Code:
    **CALCULATE POPULATION WEIGHTS
    
    gen totpop = 102701547 if year < 2007
    replace totpop = 1210193422 if year >= 2007
    
    *calculate regrict percentage by census 2001 and 2011
    gen totpop01 = 102701547 if year < 2007
    
    gen totpop11 = 1210193422 if year>= 2007
    
    bysort regcode : gen knownpoppct01 = (pop_2001/totpop01)*100 if wave == 1
    bysort regcode : gen knownpoppct11 = (pop_2011/totpop11)*100 if wave == 2
    bysort regcode : gen knownpoppct11 = (pop_2011/totpop11)*100 if wave == 3
    
    gen knownpoppct = knownpoppct01
    replace knownpoppct = knownpoppct11 if knownpoppct ==.
    
    *Calculate sample numbers by regrict by waves
    
    bysort regcode wave: gen id = _n
    bysort regcode wave: gen id2 = _N // highest numbers
    
    *calculate sample regrict percentage to total sample by waves
    bysort regcode wave: gen samppoppct01 = (id2/507624)*100 if wave == 1
    bysort regcode wave: gen samppoppct11 = (id2/643941)*100 if wave == 2
    bysort regcode wave: replace samppoppct11 = (id2/699686)*100 if wave == 3
    
    *population weights
    * knownpoppct/samppoppct by wave i.e. divide the known population percentage by the percent in the sample
    
    bysort regcode wave: gen popweight01 = knownpoppct01/samppoppct01 if wave == 1
    bysort regcode wave: gen popweight11 = knownpoppct11/samppoppct11 if wave > 1
    
    gen popweight = popweight01 if wave == 1
    replace popweight = popweight11 if wave > 1
    
    xtset regcode // Panel variable: distcode (unbalanced)
    
    foreach var in bf neo diarrhea tbcheck {
        xtreg `var' c.pcc##c.pcyn 'controls1' [pw=popweight], fe r
      
    }
    I keep getting the same error when I run my regression : weight must be constant within wave

    Do let me know if there is anything wrong in my analysis.

  • #2
    Perhaps you meant
    Code:
    xtset regcode year

    Comment


    • #3
      Year and wave are essentially the same, year simply indicates the year in which the survey data was collected, I get the error : Repeated time values within panel

      Comment


      • #4
        Withdrawn.

        Comment


        • #5
          Just bumping this post since I have not had any answers yet.

          Comment


          • #6
            Your post repeats https://www.statalist.org/forums/for...lation-weights. There was a suggestion to use reghdfe from SSC, xtreg requires weights to be constant within panels. There is no way around this restriction.

            Comment

            Working...
            X