Hi All,
I am trying to extract only the covariates ("xvars") from the e(cmdline) of a previously estimated logit model (although this should generalize to any regression model)..
I have written some code below that does the job, but I am guessing that it can be written in a more parsimonious manner -- especially as it evaluates whether there exists [if][in] qualifiers...
Any help is appreciated!
Ariel
I am trying to extract only the covariates ("xvars") from the e(cmdline) of a previously estimated logit model (although this should generalize to any regression model)..
I have written some code below that does the job, but I am guessing that it can be written in a more parsimonious manner -- especially as it evaluates whether there exists [if][in] qualifiers...
Any help is appreciated!
Ariel
Code:
webuse lbw
logit low age lwt i.race smoke if ftv <3
local xvars = subinstr("`e(cmdline)'","`e(cmd)' `e(depvar)'","",1)
local cntif = strpos("`xvars'", "if ") - 1
local cntin = strpos("`xvars'", "in ") - 1
if `cntif' > 0 {
local xvars = substr("`xvars'",1,`cntif')
}
else if `cntin' > 0 {
local xvars = substr("`xvars'",1,`cntin')
}
else {
local xvars = "`xvars'"
}
di "`xvars'"
age lwt i.race smoke
Code:
webuse lbw
logit low age lwt i.race smoke in 1/150
local xvars = subinstr("`e(cmdline)'","`e(cmd)' `e(depvar)'","",1)
local cntif = strpos("`xvars'", "if ") - 1
local cntin = strpos("`xvars'", "in ") - 1
if `cntif' > 0 {
local xvars = substr("`xvars'",1,`cntif')
}
else if `cntin' > 0 {
local xvars = substr("`xvars'",1,`cntin')
}
else {
local xvars = "`xvars'"
}
di "`xvars'"
age lwt i.race smoke
Code:
webuse lbw logit low age lwt i.race smoke local xvars = subinstr("`e(cmdline)'","`e(cmd)' `e(depvar)'","",1) local cntif = strpos("`xvars'", "if ") - 1 local cntin = strpos("`xvars'", "in ") - 1 if `cntif' > 0 { local xvars = substr("`xvars'",1,`cntif') } else if `cntin' > 0 { local xvars = substr("`xvars'",1,`cntin') } else { local xvars = "`xvars'" } di "`xvars'"
age lwt i.race smoke
Comment