Announcement

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

  • Decomposing Erreygers CI - Need results to show Categorical Variables

    Dear All,

    I am using Stata 16 and trying to decompose the Erreygers CI. My dependent variable is binary, obese. My independent variables are categorical - quintile, feedingscheme (participating or not), race(African, White, Indian, Coloured), geography(rural, urban) , gender, empl_m (yes or not), educ_m (primary, secondary, tertiary) and wgt_m (underweight, normal, over, obese)

    I am able to decompose and get results using the main independent variables - quintile, feedingscheme, gender, race, geo, empl_m, educ_m and wgt_m.

    I would like the results to show each category of the independent variables. I tried using i.quintile i.feedingscheme i.gender and so on. It gives an error "factor-variable operators not allowed".

    My commands are s follows;

    [/CODE]conindex obese [aweight=wt], rankvar(quintile) erreygers bounded limits (0 1)
    sca CI=r(CI)
    global X i.quintile i.feedingscheme i.gender i.race i.geo i.empl_m i.educ_m wgt_m
    qui sum obese [aw=wt]
    sca m_obese=r(mean)
    qui glm obese $X [aw=wt], family(binomial) link(logit)
    qui margins , dydx(*) post

    foreach x of varlist $X {
    sca b_`x'=_b[`x']
    }
    foreach x of varlist $X {
    qui{
    conindex `x' [aw=wt], rankvar(quintile) truezero
    sca CI_`x' = r(CI)
    sum `x' [aw=wt]
    sca m_`x'=r(mean)
    sca elas_`x' = b_`x'*m_`x'
    sca con_`x' = 4*elas_`x'*CI_`x'
    sca prcnt_`x' = (con_`x'/CI)*100
    }
    di "`x' elasticity:", elas_`x'
    di "`x' concentration index:", CI_`x'
    di "`x' contribution:", con_`x'
    di "`x' percentage contribution:", prcnt_`x'
    }
    matrix Aaa = nullmat(Aaa) \ (elas_`x', CI_`x', con_`x', prcnt_`x')
    }
    matrix rownames Caa= $X
    matrix colnames Caa = "Elasticity""CI""Absolute""%"
    matrix list Caa, format(%8.4f) [/CODE]

    The results are as follows:

    sca CI=r(CI)

    . global X i.quintile i.feedingscheme i.gender i.race i.geo i.empl_m i.educ_m wgt_m

    . qui sum obese [aw=wt]

    . sca m_obese=r(mean)

    . qui glm obese $X [aw=wt], family(binomial) link(logit)

    . qui margins , dydx(*) post

    .
    . foreach x of varlist $X {
    2. sca b_`x'=_b[`x']
    3. }
    factor-variable operators not allowed


    My data is as follows:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float obese byte quintile float(feedingscheme gender race geo empl_m educ_m wgt_m)
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . 0 0 1
    0 1 0 1 1 0 0 0 1
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . 0 0 1
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . 1 0 2
    . . . . . . 1 0 2
    . . . . . . 1 0 2
    . . . . . . . . .
    0 2 1 1 1 0 1 0 2
    . . . . . . 1 0 2
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    0 3 0 1 1 0 . . .
    0 3 0 0 1 0 . . .
    . . . . . . . . .
    . . . . . . . . .
    . 3 0 1 1 0 . . .
    . . . . . . 0 0 3
    . . . . . . . . .
    . . . . . . . . .
    0 3 0 0 1 0 1 0 1
    0 3 0 1 1 0 1 0 1
    . . . . . . 1 0 1
    . . . . . . 1 0 1
    0 1 0 0 1 0 . . .
    0 1 0 0 1 0 . . .
    . 1 . 0 1 0 . . .
    0 1 0 0 1 0 . . .
    . . . . . . . . .
    . . . . . . . . .
    0 1 . 1 1 0 . . .
    0 1 0 1 1 0 0 0 3
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    0 1 0 0 1 0 0 0 3
    0 1 0 1 1 0 0 0 1
    0 1 0 1 1 0 0 0 3
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    0 1 0 1 1 0 . . .
    . . . . . . . . .
    . . . . . . . . .
    0 1 0 1 1 0 . . .
    . 1 0 0 1 0 . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . 0 1 1
    . . . . . . . . .
    . . . . . . . . .
    . . . . . . 0 0 1
    . . . . . . . . .
    . . . . . . 0 1 1
    0 2 0 1 1 0 0 1 1
    . . . . . . 0 1 1
    0 1 . 0 1 0 0 0 0
    . . . . . . . . .
    . . . . . . . . .
    0 2 0 0 1 0 1 0 3
    0 2 1 1 1 0 1 0 3
    . 2 . 1 1 0 1 0 3
    . . . . . . . . .
    1 2 0 1 1 0 1 0 3
    . . . . . . 0 2 2
    0 2 0 1 1 0 1 0 3
    . . . . . . 0 0 3
    . . . . . . 0 0 3
    . . . . . . . . .
    . . . . . . 0 1 2
    . . . . . . 0 1 2
    . . . . . . 0 1 3
    . . . . . . 0 1 3
    . . . . . . 0 0 3
    . . . . . . . . .
    0 1 1 1 1 0 0 0 3
    . . . . . . . . .
    . . . . . . 0 1 2
    . . . . . . 0 1 2
    0 1 0 0 1 0 0 0 3
    1 1 0 1 1 0 0 0 3
    . . . . . . 0 0 3
    . . . . . . 0 0 3
    . . . . . . . . .
    . 1 1 0 1 0 0 1 2
    end
    label values obese obese5
    label def obese5 0 "Not_Obese", modify
    label def obese5 1 "Obese", modify
    label values feedingscheme feedingscheme5
    label def feedingscheme5 0 "nfscheme", modify
    label def feedingscheme5 1 "fscheme", modify
    label values gender gender5
    label def gender5 0 "Male", modify
    label def gender5 1 "Female", modify
    label values race race5
    label def race5 1 "African", modify
    label values geo geo5
    label def geo5 0 "Rural", modify
    I also tried decomposing using categorical variables but that is not allowed.

    Please advise.

    Regards
    Nthato


    .

  • #2
    Hi Nthato,

    A simple way to address your problem is to create dummy variables instead of using factor notations. Let's take gender as an example, you can create dummies for this variable by typing: tab gender5, gen(gender_). This command will give you two dummies: gender_1 (=1 if male and 0 otherwise) and gender_2 (=1 if female and 0 otherwise). Do the same thing for other variables (e.g., quintile feedingscheme gender race geo empl_m educ_m) that you want to include into the decomposition. Now, your macro X should be:
    global X "gender_1 ... put other variables here" (here I treated gender_1 as a compared group and gender_2 as a reference group, you can change this variable to meet your desire).

    Hope this helps.

    Comment


    • #3
      Hi Dung,

      Thanks for the response. It worked!

      Just to be clear, I do not list the reference dummy variable?

      Regards
      Nthato
      Last edited by Nthato Ras; 06 Jul 2022, 06:28. Reason: Rephrasing the question

      Comment


      • #4
        Hi Nthato,

        Glad it worked. You don't need to list the reference group, though there is no harm doing so. If you include the reference group, Stata eventually will drop one, either gender_1 or gender_2 (Stata will drop one with a lower proportion between the two).

        Comment


        • #5
          Thanks Dung.

          Just a follow up question - The total of my percentage contribution of the decomposed CI does not add up to 100% - it is actually over 100%. I checked a few papers and found that most do not add up to 100%, some are under and others above. This boggles my mind because my mathematical understanding tells me that total contribution should be 100%.

          These are my results below: The total contribution adds up to 120%. Is this correct?

          Elasticity CI Absolute %
          quintile 0.0537 0.1416 0.0304 65.0554
          fprogram_1 0.0098 0.2221 0.0087 18.6556
          gender_1 -0.0080 -0.0053 0.0002 0.3594
          race_1 -0.0036 0.4340 -0.0062 -13.2124
          race_2 -0.0147 -0.0776 0.0046 9.7420
          race_3 -0.0045 0.0897 -0.0016 -3.4684
          geo_2 0.0007 0.1624 0.0004 0.9514
          level_2 0.0086 -0.0178 -0.0006 -1.3136
          level_3 0.0100 0.3638 0.0146 31.2323
          employed_2 0.0018 0.1243 0.0009 1.9603
          mbmi_2 0.0142 -0.0375 -0.0021 -4.5606
          mbmi_3 0.0205 -0.0199 -0.0016 -3.4944
          mbmi_4 0.0910 0.0304 0.0111 23.6876

          Please advise
          Nthato
          Last edited by Nthato Ras; 08 Jul 2022, 00:56.

          Comment


          • #6
            Hi Nthato,

            The percentage contribution does not need to add up to 100% because as you may notice the simple formula of the decomposition analysis. That is, decomposition = explained part (120%) + unexplained part (-20%). That says in your case, the excess 20% could be due to unexplained part. Normally, when reporting the decomposition results, you should report both parts, which should add up to 100%.

            Comment


            • #7
              Thank you so much Dung.

              So, is the -20% my residual?

              Comment


              • #8
                Originally posted by Nthato Ras View Post
                Thank you so much Dung.

                So, is the -20% my residual?
                Yes. In other words, your residual should be -20%.

                Comment


                • #9
                  Thanks Dung

                  Comment

                  Working...
                  X