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
Issue With Quarterly Data FormatHello Stata community, I am having an issue when trying to create a simple "difference" variable, be…
rifhdreg svy optionDear list members, I have been using the rifhdreg command a lot and it worked out very well. The ba…
Requeasting for the exact command to simpson diversifcation index in stataHello, Dear all, I am new for the stata software. Would you please show me the appropriate command t…
x*x Frequency Table Across A VariableHi Everyone, I am working with a datset that has following variables: 1) mrn: unique identifier 2)…
Export SEM models into formatted tablesDear all, Because I have to use FIML in my analyses, I'll have to rewrite my code from using the 'r…
Subscribe to:
Post Comments (Atom)
0 Response to Logistic odds ratio in loops
Post a Comment