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:
I also tried decomposing using categorical variables but that is not allowed.
Please advise.
Regards
Nthato
.
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
Please advise.
Regards
Nthato
.
Comment