Skip to content

Commit

Permalink
Merge pull request #11 from fmg-jluchman/main
Browse files Browse the repository at this point in the history
-domme- to v 1.2.0; sync with -domin-
  • Loading branch information
jluchman authored Jan 27, 2024
2 parents c3a8a33 + 984b8f1 commit 0b32a61
Show file tree
Hide file tree
Showing 9 changed files with 729 additions and 957 deletions.
74 changes: 45 additions & 29 deletions domin.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! domin version 3.5.0 8/14/2023 Joseph N. Luchman
*! domin version 3.5.1 1/12/2024 Joseph N. Luchman
// version information at end of file

**# Pre-program definition
Expand Down Expand Up @@ -33,7 +33,7 @@ if replay() {
**# Program definition and argument checks
syntax varlist(min = 1 ts) [in] [if] [aw pw iw fw] , ///
[Reg(string) Fitstat(string) Sets(string) All(varlist fv ts) ///
noCONditional noCOMplete EPSilon CONSmodel REVerse noESAMPleok mi miopt(string)] // remove direct mi support - make it into a wrapper
noCONditional noCOMplete EPSilon CONSmodel REVerse noESAMPleok mi miopt(string)]

if strlen("`epsilon'") {
local esampleok "esampleok"
Expand Down Expand Up @@ -64,23 +64,21 @@ else if strlen("`epsilon'") & strlen("`e(title)'") local title "Epsilon-based `r
else local title "Custom user analysis"

matrix `domwgts' = r(domwgts)
ereturn post `domwgts' [`weight'`exp'], depname(`dv') obs(`=`r(N)'') esample(`touse')
ereturn post `domwgts' [`weight'`exp'], depname(`dv') obs(`=r(N)') esample(`touse')

**# Ereturn scalars
ereturn scalar N = `=r(N)'

matrix `domwgts' = r(domwgts)*J(colsof(r(domwgts)), 1, 1)
if strlen("`epsilon'") ereturn scalar fitstat_o = `=`domwgts'[1,1]'
else ereturn scalar fitstat_o = `=`domwgts'[1,1] + r(allfs) + r(consfs)'
else ereturn scalar fitstat_o = `=r(fullfs) + r(allfs) + r(consfs)'

if `:list sizeof all' ereturn scalar fitstat_a = `=r(allfs)'
if strlen("`consmodel'") ereturn scalar fitstat_c = `=r(consfs)'

if strlen("`setcnt'") {
if strlen("`setcount'") {

ereturn hidden scalar setcnt = `setcnt'
ereturn hidden scalar setcount = `setcount'

forvalues x = 1/`setcnt' {
forvalues x = 1/`setcount' {

fvunab set`x': `set`x''

Expand All @@ -90,10 +88,10 @@ if strlen("`setcnt'") {

}

else ereturn hidden scalar setcnt = 0
else ereturn hidden scalar setcount = 0

**# Ereturn macros
ereturn hidden local dtitle "`title'"
ereturn hidden local disp_title "`title'"

ereturn hidden local reverse "`reverse'"

Expand Down Expand Up @@ -141,10 +139,10 @@ if !strlen("`conditional'") {
ereturn matrix cdldom = `cdldom'
}

matrix `ranks' = r(ranks)
matrix `ranks' = r(ranks)
ereturn matrix ranking = `ranks'

matrix `stdzd' = r(stdzd)
matrix `stdzd' = r(stdzd)
ereturn matrix std = `stdzd'

Display
Expand Down Expand Up @@ -174,12 +172,12 @@ tokenize `diivs'

local dv = abbrev("`e(depvar)'", 10)

display _newline "{txt}General dominance statistics: `e(dtitle)'" _newline ///
display _newline "{txt}General dominance statistics: `e(disp_title)'" _newline ///
"{txt}Number of obs{col 27}={res}{col 40}" %12.0f e(N)

display "{txt}Overall Fit Statistic{col 27}={res}{col 36}" %16.4f e(fitstat_o)

if !missing(e(fitstat_a)) display "{txt}All Subsets Fit Stat.{col 27}={res}{col 36}" %16.4f e(fitstat_a)
if !missing(e(fitstat_a)) display "{txt}All Sub-models Fit Stat.{col 27}={res}{col 36}" %16.4f e(fitstat_a)

if !missing(e(fitstat_c)) display "{txt}Constant-only Fit Stat.{col 27}={res}{col 36}" %16.4f e(fitstat_c)

Expand Down Expand Up @@ -222,7 +220,7 @@ if `cpttest' {

if e(estimate) == "dominance" & `=`cpttest'*`cdltest'' {

display _newline "{res}Strongest dominance designations" _newline
display _newline "{txt}Strongest dominance designations" _newline

tempname bestdom cdl gen decision

Expand Down Expand Up @@ -261,7 +259,7 @@ if e(estimate) == "dominance" & `=`cpttest'*`cdltest'' {

local names `:colnames e(b)'

mata: display((select(vec(tokens(st_local("names"))':+((st_matrix("`bestdom'"):==1):*" completely dominates "):+tokens(st_local("names")))', ///
mata: display(("{txt}", select(vec(tokens(st_local("names"))':+((st_matrix("`bestdom'"):==1):*" completely dominates "):+tokens(st_local("names")))', ///
regexm(vec(tokens(st_local("names"))':+((st_matrix("`bestdom'"):==1):*" completely dominates "):+tokens(st_local("names")))', ///
"completely dominates")) , ///
select(vec(tokens(st_local("names"))':+((st_matrix("`bestdom'"):==2):*" conditionally dominates "):+tokens(st_local("names")))', ///
Expand All @@ -275,17 +273,17 @@ if e(estimate) == "dominance" & `=`cpttest'*`cdltest'' {

}

if `=e(setcnt)' {
if `=e(setcount)' {

forvalues x = 1/`=e(setcnt)' {
forvalues x = 1/`=e(setcount)' {

display "{txt}Variables in set`x': `e(set`x')'"

}

}

if strlen("`e(all)'") display "{txt}Variables included in all subsets: `e(all)'"
if strlen("`e(all)'") display "{txt}Variables included in all sub-models: `e(all)'"

end

Expand Down Expand Up @@ -381,17 +379,17 @@ void domin_2mata(
/*set processing*/
if ( strlen(sets) ) {
/*setup parsing sets - bind on parentheses*/
/*setup parsing sets - bind on parentheses*/
parser = tokeninit(" ", "", "()")
tokenset(parser, sets)
/*get all sets and remove parentehses*/
iv_sets = tokengetall(parser)
iv_sets = substr(iv_sets, 2, strlen(iv_sets):-2)
st_local("setcnt", strofreal( length(iv_sets) ) )
st_local("setcount", strofreal( length(iv_sets) ))
for (set=1; set<=length(iv_sets); set++) {
st_local("set"+strofreal(set), iv_sets[set] )
st_local("set"+strofreal(set), iv_sets[set])
rc = _stata("fvunab waste: " + iv_sets[set], 1)
if ( rc ) {
Expand Down Expand Up @@ -457,7 +455,13 @@ void domin_2mata(
stata("generate byte " + marks[1] + " = e(sample)", 1)
stata("count if " + marks[1], 1)
if (strmatch(weight, "fweight*") | strmatch(weight, "iweight*")) {
stata("summarize " + marks[1] + " if " + marks[1] +
" [" + weight + "]", 1)
}
else stata("count if " + marks[1], 1)
obs = st_numscalar("r(N)")
Expand All @@ -475,7 +479,13 @@ void domin_2mata(
stata("markout " + marks[1] + " " + marks[2] +
" " + invtokens(ivs) + " " + all, 1)
stata("count if " + marks[1], 1)
if (strmatch(weight, "fweight*") | strmatch(weight, "iweight*")) {
stata("summarize " + marks[1] + " if " + marks[1] +
" [" + weight + "]", 1)
}
else stata("count if " + marks[1], 1)
obs = st_numscalar("r(N)")
Expand Down Expand Up @@ -570,7 +580,7 @@ void domin_2mata(
}
cons_fitstat = 0
cons_fitstat = 0
if ( strlen(consmodel) ) {
Expand Down Expand Up @@ -677,8 +687,9 @@ void domin_2mata(
st_local("touse", marks[1])
st_local("dv", dv)
st_numscalar("r(allfs)", model_specs.get("all_fitstat"))
st_numscalar("r(consfs)", model_specs.get("cons_fitstat"))
st_numscalar("r(allfs)", all_fitstat)
st_numscalar("r(consfs)", cons_fitstat)
st_numscalar("r(fullfs)", full_fitstat)
}
Expand Down Expand Up @@ -943,8 +954,13 @@ end
- updates to dominance.mata (to 0.1.0)
- updated 'epsilon' method to use st_view() instead of st_data()
- 'epsilon' method accepts weights
**
// 3.5.1 - January 12, 2024
- fixed references to 'all subsets' - should be 'all sub-models'
- fixed error in docuementation of -rforest- Example 11; needed -noesampleok-
- removed redundant e(N) setting
- fixed N computation with -fweight- and -iweight-
---
future domin
** planned ** - depreciated by -domin2-'s bmaregress interface; eventually will be defunct and enveloped by its interface
*/
8 changes: 4 additions & 4 deletions domin.sthlp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{smcl}
{* *! version 3.5.0 August 14, 2023 J. N. Luchman}{...}
{* *! version 3.5.1 January 12, 2024 J. N. Luchman}{...}
{cmd:help domin}

{title:Title}
Expand Down Expand Up @@ -469,7 +469,7 @@ when overall model fit statistics are used that decrease with better fit (e.g.,
{phang} {stata end} {p_end}
{phang} {stata rforest price mpg headroom weight, type(reg)} {p_end}
{phang} {stata matrix list e(importance)} {p_end}
{phang} {stata domin price mpg headroom weight, reg(fitdom, reg_fd(rforest, type(reg)) postestimation(myRFr2) fitstat_fd(e(r2))) fitstat(e(fitstat))} {p_end}
{phang} {stata domin price mpg headroom weight, reg(fitdom, reg_fd(rforest, type(reg)) postestimation(myRFr2) fitstat_fd(e(r2))) fitstat(e(fitstat)) noesampleok} {p_end}
{marker remark}{...}
Expand Down Expand Up @@ -554,7 +554,7 @@ when they do not follow the traditional {it:depvar indepvars} format. As long a
be expressed in some way that can be evaluated in {it:depvar indepvars} format, any analysis could be
dominance analyzed.

{pstd}Any program used as a wrapper by {cmd:domin} must accept an {help if} statement in its {help syntax}.
{pstd}Any program used as a wrapper by {cmd:domin} must accept an {help if} statement, a comma, and at least one (possibly optional) option argument in its {help syntax}.
It is recommended that wrapper programs parse the inputs as a {it:varlist} as well (see Example #9a).

{pstd}A third wrapper program, {cmd:fitdom}, takes inspiration from the
Expand Down Expand Up @@ -608,7 +608,7 @@ Please cite as:
{title:Author}

{p 4}Joseph N. Luchman{p_end}
{p 4}Principal Scientist{p_end}
{p 4}Research Fellow{p_end}
{p 4}Fors Marsh{p_end}
{p 4}Arlington, VA{p_end}
{p 4}jluchman@forsmarsh.com{p_end}
Expand Down
Loading

0 comments on commit 0b32a61

Please sign in to comment.