Announcement

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

  • weighting using ipfweight

    Hi there,

    I’m working with data from an online survey and trying to apply weights so the sample reflects the general population in terms of gender, age groups, and educational attainment.

    However, after applying the weights, I noticed that the number of observations appears to change—for example, for the variable pa. I suspect there might be an issue with either the weighting code or my interpretation of the results.

    Any guidance would be much appreciated.


    recode GENDER 2=1 1=0, gen(female)

    gen java = 0
    replace java = 1 if region == 1

    tab java if sample == 1


    gen other = 0
    replace other = 1 if region == 0

    tab other if sample == 1


    gen age_cat1 = 0
    replace age_cat1 = 1 if age_cat == 1

    tab age_cat1 if sample == 1


    gen age_cat2 = 0
    replace age_cat2 = 1 if age_cat == 2

    tab age_cat2 if sample == 1

    gen age_cat3 = 0
    replace age_cat3 = 1 if age_cat == 3

    tab age_cat3 if sample == 1


    gen age_cat4 = 0
    replace age_cat4 = 1 if age_cat == 4

    tab age_cat4 if sample == 1


    gen age_cat5 = 0
    replace age_cat5 = 1 if age_cat == 5

    tab age_cat5 if sample == 1

    gen lessthanuni = 0
    replace lessthanuni = 1 if educ == 0

    tab lessthanuni if sample == 1



    gen uni = 0
    replace uni = 1 if educ == 1

    tab uni if sample == 1



    ipfweight female java age_cat1 age_cat2 age_cat3 age_cat4 age_cat5 uni, gen(weight) val(50.5 49.5 33.83 66.17 76.8 23.2 77.3 22.7 79.3 20.7 83.4 16.6 89.2 10.8 89.8 10.2) maxit(25)

    su weight


    tab weight

    ipfweight female java age_cat1 age_cat2 age_cat3 age_cat4 age_cat5 uni, gen(weighttrim) val(50.5 49.5 33.83 66.17 76.8 23.2 77.3 22.7 79.3 20.7 83.4 16.6 89.2 10.8 89.8 10.2) up (6) maxit(25)

    su weighttrim

    tab pa if sample == 1


    tab pa [iw=weighttrim] if sample == 1

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str14 RESPONDENT_ID byte GENDER float(region age_cat educ pa sample)
    "16DozgvLDD3522" 2 1 2 1 0 1
    "ruZjlGMLDD3522" 1 1 1 0 0 1
    "hLKOmJ3LDD3522" 1 1 1 1 0 1
    "fbK7XN6LDD3522" 1 1 2 0 0 1
    "OotjYKqLDD3522" 1 1 2 1 0 1
    "pXEh0kpLDD3522" 2 1 2 1 0 1
    "MkWqwP6LDD3522" 1 0 2 0 0 1
    "mKjULGzLDD3522" 2 1 1 0 0 1
    "U8FwM14LDD3522" 1 1 3 0 0 1
    "PhL0tmULDD3522" 2 1 1 1 0 1
    "jjCHf03LDD3522" 1 0 4 0 0 1
    "hHgYQ5nLDD3522" 2 1 3 1 0 1
    "kWpVOOKLDD3522" 2 1 2 1 0 1
    "E7MYYJPLDD3522" 2 1 2 1 0 1
    "3SWQMU9LDD3522" 2 1 3 0 0 1
    "zIViTJjLDD3522" 1 1 1 0 0 1
    "X5Fw28DLDD3522" 2 1 1 1 0 1
    "eLWKgFPLDD3522" 2 1 1 1 0 1
    "JIOsJiULDD3522" 2 1 1 1 0 1
    "URqTDGVLDD3522" 1 0 3 1 0 1
    "1g67T3ILDD3522" 2 0 1 1 0 1
    "7MQcnZFLDD3522" 1 1 4 1 0 1
    "8xfcGGsLDD3522" 1 1 5 1 0 1
    "Hnx7TpvLDD3522" 2 1 2 1 0 1
    "QpB3IlzLDD3522" 1 1 1 0 . 1
    "Uq2UOXKLDD3522" 2 1 1 0 0 1
    "65nvJCOLDD3522" 2 0 1 1 0 1
    "5HiVMlzLDD3522" 2 0 1 1 0 1
    "fgwp0VlLDD3522" 1 1 2 1 0 1
    "zwGv5nCLDD3522" 2 1 2 1 0 1
    "bHogWjiLDD3522" 2 1 2 1 0 1
    "kBxaxJZLDD3522" 2 0 1 1 0 1
    "5S9NFv7LDD3522" 1 1 3 0 0 1
    "3onPgdvLDD3522" 1 1 3 1 0 1
    "zM7eqIiLDD3522" 1 1 1 0 0 1
    "Qsh4q2mLDD3522" 1 1 3 0 0 1
    "5RAKJluLDD3522" 2 1 1 1 0 1
    "4UVXW9bLDD3522" 2 1 4 0 0 0
    "DiJxJX3LDD3522" 1 0 1 0 0 1
    "cm3nAjbLDD3522" 1 1 1 1 0 1
    "FChBax5LDD3522" 1 1 4 0 0 1
    "GpEkshvLDD3522" 2 1 1 0 0 1
    "iq5glVmLDD3522" 2 0 4 0 0 1
    "HfC0BhTLDD3522" 2 0 1 1 0 1
    "UMASMArLDD3522" 1 1 2 0 0 1
    "g01L7OELDD3522" 1 1 1 0 0 1
    "TE2F5WXLDD3522" 2 1 1 1 0 1
    "93vAEOdLDD3522" 2 1 1 0 0 1
    "5jqTxDRLDD3522" 1 1 1 1 0 1
    "US0cN4rLDD3522" 2 0 3 1 0 1
    "l3DKvyGLDD3522" 1 0 3 0 0 1
    "jGPdBGaLDD3522" 1 1 1 1 0 1
    "DmaMbp3LDD3522" 1 0 1 0 0 1
    "aydAWJvLDD3522" 1 1 2 1 0 1
    "AcsQwdaLDD3522" 1 1 3 1 0 1
    "kCVmab2LDD3522" 1 1 4 1 0 1
    "33UE08QLDD3522" 2 0 1 1 0 1
    "PWvBRPxLDD3522" 1 1 5 1 0 1
    "fYGbR9WLDD3522" 2 0 3 1 0 1
    "f5x8az4LDD3522" 1 1 3 1 0 1
    "8gBgVBiLDD3522" 2 1 3 0 0 1
    "wkvSggcLDD3522" 1 1 4 1 0 1
    "ZPUi5dSLDD3522" 1 1 1 1 0 1
    "p1VfQqmLDD3522" 1 0 1 1 0 1
    "kE7lywiLDD3522" 2 1 1 1 0 1
    "US6Rp5JLDD3522" 1 1 1 0 0 1
    "0rDExfhLDD3522" 2 1 2 1 0 1
    "NNqg7TOLDD3522" 2 1 2 1 0 1
    "xozjQK3LDD3522" 2 1 2 1 0 1
    "KsEnORYLDD3522" 2 1 2 0 0 1
    "uoc1y3fLDD3522" 1 1 1 1 0 1
    "pJuEqjaLDD3522" 2 1 1 1 0 1
    "4WZfBRILDD3522" 2 1 4 1 0 1
    "Kpign04LDD3522" 1 1 4 1 0 1
    "P9EtUqhLDD3522" 2 0 4 1 0 1
    "6g7UauBLDD3522" 2 1 1 1 0 1
    "wRwcZ7XLDD3522" 1 1 1 1 0 1
    "JWvO5XLLDD3522" 2 1 1 1 0 1
    "wCDbJQOLDD3522" 2 1 2 1 0 1
    "iinuSkeLDD3522" 1 1 1 1 0 1
    "fosa201LDD3522" 1 1 3 0 0 1
    "NY8nogiLDD3522" 2 1 3 1 0 1
    "fzNsgU2LDD3522" 1 1 3 0 0 1
    "ytJEOaYLDD3522" 2 0 3 0 0 1
    "ApisEnzLDD3522" 2 1 2 1 0 1
    "Pnko8gfLDD3522" 1 1 5 1 0 1
    "yq12Ul1LDD3522" 2 1 5 1 0 1
    "zOhmBx4LDD3522" 1 1 1 1 0 1
    "3w1WzWkLDD3522" 1 1 2 0 0 1
    "f41nGzWLDD3522" 1 1 2 0 0 1
    "4Hx3GzwLDD3522" 1 1 3 1 0 1
    "svQdfuFLDD3522" 2 0 1 1 0 1
    "Ux9k7hULDD3522" 1 1 2 0 0 1
    "GtdinyfLDD3522" 2 1 3 1 0 1
    "bm4UholLDD3522" 1 0 1 0 0 1
    "j2vGuYlLDD3522" 2 1 1 1 0 1
    "ADnQswmLDD3522" 2 1 1 1 0 1
    "omgW262LDD3522" 2 1 3 0 0 1
    "SiPudocLDD3522" 2 1 2 1 0 1
    "WFzs5ArLDD3522" 2 1 2 1 0 1
    end
Working...
X