Dear statalist,
I'm using a logistic regression in a loop, which I later on use in a coefplot
First I used margins with the command below and this resulted in the first figure:
webuse lbw
global outcomes_binary "low smoke"
global outcomes_continuous "bwt"
global outcomes "$outcomes_binary $outcomes_continuous"
global covariates "age lwt ptl ht ui"
foreach y of global outcomes_binary {
logit `y' $covariates
margins, dydx(*) post
mat b_`y' = r(table)
mat b_`y' = b_`y'[1..6,1...]'
mat b_`y' = b_`y'[1...,1], b_`y'[1...,5], b_`y'[1...,6], b_`y'[1...,4]
}
foreach y of global outcomes_continuous {
reg `y' $covariates
margins, dydx(*) post
mat b_`y' = r(table)
mat b_`y' = b_`y'[1..6,1...]'
mat b_`y' = b_`y'[1...,1], b_`y'[1...,5], b_`y'[1...,6], b_`y'[1...,4]
}
local i = 1
foreach var of global covariates {
mat `var' = J(1,4,0)
foreach y of global outcomes {
mat `var' = `var' \ b_`y'[`i',1...]
}
mat `var' = `var'[2...,1...]
mat rownames `var' = $outcomes_binary $outcomes_continuous $outcomes_ordinal0 $outcomes_ordinal5 $outcomes_ordinal4
mat colnames `var' = `var' ci_l ci_h
local i = `i' + 1
}
coefplot matrix(age[,1]), ci((age[,2] age[,3])) ///
|| matrix(lwt[,1]), ci((lwt[,2] lwt[,3])) ///
|| matrix(ptl[,1]), ci((ptl[,2] ptl[,3])) ///
||, scheme(s1color) xline(0) byopts(row(1)) xlab(-200(200)200 ,format(%9.0f)) mlabel mlabposition(2) format(%9.3f)
Array
I would like to change the marginal effects into odds ratios, but when I try this command:
foreach y of global outcomes_binary {
logistic `y' $covariates, or
mat b_`y' = r(table)
mat b_`y' = b_`y'[1..6,1...]'
mat b_`y' = b_`y'[1...,1], b_`y'[1...,5], b_`y'[1...,6], b_`y'[1...,4]
}
Something goes wrong and the figure is incomplete (smoke & bwt are missing).
Array
Can anyone help me to fix the command for storing odds ratios in loops?
Thanks in advance!
Regards, Anouk
Related Posts with Logistic odds ratio in loops
Estimated coefficients structural VAR - svarHi, I am trying to estimate the coefficients of an svar model with exogenous variables. I understan…
Multicollinearity in regression analysisI need to test multicollinearity for my data set. I made the correlation matrix and I notice a corre…
Converting Date or birth to AgeHello, It's first time I am using this forum. I have previously converted successfully date of birth…
Regrouping variablesHello everyone ! We are working on a project on Stata where we have to work on this regression : ln…
Matching subjects across multiple variables and within variableI have a dataset where there are several variables that I'm being asked to match and come up with so…
Subscribe to:
Post Comments (Atom)
0 Response to Logistic odds ratio in loops
Post a Comment