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
Firth's method for Cox RegressionHi all, Can anyone guide me how to carry out a Firth Penalized Cox Regression with STATA? One of m…
Creating an inflation index seriesHello, From the data below, you can see that i have the inflation for a few years. However, this ca…
Do I need to add main effect in a regression model with a Difference value between two variables?Hi, Here is my regression model: regress y x1 x2 x3_x4; /* x3_x4 = x3 - x4 */ Do I need to add x3…
Problem with propensity score matchingHello - I am running the following code for propensity score matching and then running a model on th…
GLM vs. GEE for crossed random effectsI'm doing education research and looking at the effect of a particular study tool. My treatment was …
Subscribe to:
Post Comments (Atom)
0 Response to Logistic odds ratio in loops
Post a Comment