Skip to content

Commit

Permalink
Fixed broken compatibility with Stata < 15 from adding mvnormal() / g…
Browse files Browse the repository at this point in the history
…hkdraws(0) in 8.7.3
  • Loading branch information
droodman committed Apr 18, 2024
1 parent 049aafd commit 0ab886b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
29 changes: 15 additions & 14 deletions cmp.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! cmp 8.7.8 18 March 2024
*! cmp 8.7.9 18 April 2024
*! Copyright (C) 2007-24 David Roodman

* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -36,7 +36,7 @@ end

cap program drop _cmp
program define _cmp
version 11.0
version 11

if replay() {
if "`e(cmd)'" != "cmp" error 301
Expand Down Expand Up @@ -1073,7 +1073,7 @@ end

cap program drop ParseEqs
program define ParseEqs
version 11.0
version 11
local _cons _cons
global parse_d 0

Expand Down Expand Up @@ -1273,7 +1273,7 @@ end
* Parses and implements corr() option as constraint set
/*cap program drop ParseCorr
program define ParseCorr, rclass
version 11.0
version 11
if `"`0'"' == "."
Expand Down Expand Up @@ -1307,7 +1307,7 @@ end*/
* These lines are in a subroutine to work around Stata parsing bug with "if...quietly {"
cap program drop DoInitSearch
program define DoInitSearch, rclass
version 11.0
version 11
`*' // run InitSearch
tempname b
mat `b' = r(b)
Expand Down Expand Up @@ -1490,7 +1490,7 @@ end

cap program drop NoEstimate
program NoEstimate, eclass
version 11.0
version 11
ereturn post `0'
ereturn local title Mixed-process regression--initial fits only
ereturn local cmdline cmp `cmdline'
Expand All @@ -1499,7 +1499,7 @@ end

cap program drop Estimate
program Estimate, eclass
version 11.0
version 11
syntax if/ [fw aw pw iw], [auxparams(string) psampling(string) svy subpop(passthru) autoconstrain paramsdisplay(string) ///
modopts(string) mlopts(string) iterate(passthru) init(string) cmpinit(string) constraints(string) _constraints(string) technique(string) vce(string) 1only quietly resteps(string) redraws(string) interactive lf *]

Expand Down Expand Up @@ -1720,7 +1720,7 @@ end
// returns ordered row vector of the categories
cap program drop GroupCategoricalVar
program define GroupCategoricalVar, rclass
version 11.0
version 11
syntax [if], cmp_eqno(string) [predict(string)]
tempname cat num_cuts
if "`predict'"=="" {
Expand All @@ -1743,7 +1743,7 @@ end
cap program drop LabelMprobitEq
program LabelMprobitEq
version 11.0
version 11
// try to name the eq after the outcome's label
local 3: label (_cmp_y`4') `3'
global cmp_eq`1': label (${parse_y`2'}) `3'
Expand All @@ -1756,7 +1756,7 @@ end
// as well as constraints on rho's needed for equations with non-overlapping samples
cap program drop InitSearch
program InitSearch, rclass
version 11.0
version 11
syntax [aw fw iw pw] if/, [auxparams(string) adjustprobitsample nodrop svy 1only quietly mlopts(string)]
local if (`if')
tempname sig beta gamma betavec gammavec auxparamvec _auxparamvec sigvec atanhrho V mat_cons omit
Expand Down Expand Up @@ -2197,7 +2197,7 @@ end
cap program drop Display
program Display, eclass
version 11.0
version 11
novarabbrev {
syntax [, Level(real `c(level)') RESULTsform(string) *]
_get_eformopts, soptions eformopts(`options') allowed(hr shr IRr or RRr)
Expand Down Expand Up @@ -2499,7 +2499,7 @@ end
// for same reason, deletes any showeqns option
cap program drop _get_mldiopts
program define _get_mldiopts, sclass
version 11.0
version 11
syntax, [NOHeader NOFOOTnote /*first*/ neq(string) SHOWEQns PLus NOCNSReport NOOMITted vsquish NOEMPTYcells BASElevels ALLBASElevels cformat(string) pformat(string) sformat(string) NOLSTRETCH coeflegend *]
foreach opt in neq cformat pformat sformat {
if `"``opt''"' != "" {
Expand All @@ -2512,7 +2512,7 @@ end
cap program drop CheckCondition
program define CheckCondition
version 11.0
version 11
if "`1'" != "" {
syntax varlist(ts fv) [aw iw]
tempname XX c
Expand All @@ -2537,13 +2537,14 @@ end
cap program drop cmp_error
program define cmp_error
version 11.0
version 11
noi di as err `"`2'"'
cmp_clear
exit `1'
end
* Version history
* 8.7.9 Fixed broken compatibility with Stata < 15 from adding mvnormal() / ghkdraws(0) in 8.7.3
* 8.7.8 Fixed crash on ghkrdaws(0) with random effects.
* 8.7.7 Prevent crash in a gamma model with ordered probits, when deleting obs because of eq interdependencies empties a category
* Support tech(nm)
Expand Down
15 changes: 9 additions & 6 deletions cmp.mata
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* cmp 8.7.8 18 March 2024
/* cmp 8.7.9 18 April 2024
Copyright (C) 2007-24 David Roodman
This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -908,19 +908,19 @@ real colvector cmp_model::vecmultinormal(real matrix E, real matrix F, real matr
else
Phi = _ghk2_2 (ghk2DrawSet, F, E, Sig, ghkAnti, GHKStart)
else {
Phi = mvnormalcv(F, E, J(1,cols(E),0), vech(Sig)')
Phi = _mvnormalcv(F, E, J(1,cols(E),0), vech(Sig)')
if (todo)
mvnormalcvderiv(F, E, J(1,cols(E),0), vech(Sig)', dPhi_dF, dPhi_dE, dM, dPhi_dSig)
_mvnormalcvderiv(F, E, J(1,cols(E),0), vech(Sig)', dPhi_dF, dPhi_dE, dM, dPhi_dSig)
}
else if (ghk2DrawSet != .)
if (todo)
Phi = _ghk2_d(ghk2DrawSet, E, Sig, ghkAnti, GHKStart, dPhi_dE, dPhi_dSig)
else
Phi = _ghk2 (ghk2DrawSet, E, Sig, ghkAnti, GHKStart)
else {
Phi = mvnormalcv(J(1, cols(E), mindouble()), E, J(1,cols(E),0), vech(Sig)')
Phi = _mvnormalcv(J(1, cols(E), mindouble()), E, J(1,cols(E),0), vech(Sig)')
if (todo)
mvnormalcvderiv(J(1, cols(E), invnormal(Phi*1e-20)), E, J(1,cols(E),0), vech(Sig)', dPhi_dF, dPhi_dE, dM, dPhi_dSig)
_mvnormalcvderiv(J(1, cols(E), invnormal(Phi*1e-20)), E, J(1,cols(E),0), vech(Sig)', dPhi_dF, dPhi_dE, dM, dPhi_dSig)
}
if (N_perm==1) {
Expand All @@ -934,6 +934,9 @@ real colvector cmp_model::vecmultinormal(real matrix E, real matrix F, real matr
return (Phi)
}
real colvector _mvnormalcv(a,b,c,d) return (mvnormalcv(a,b,c,d))
void _mvnormalcvderiv(a,b,c,d,e,f,g,h) return (mvnormalcvderiv(a,b,c,d,e,f,g,h))
// compute the log likelihood associated with a given error data matrix, for "continuous" variables
// Sig is the assumed covariance for the full error set and inds marks the observed variables assumed to have a joint normal distribution,
// i.e., the ones not censored
Expand Down Expand Up @@ -2390,4 +2393,4 @@ void cmp_model::SaveSomeResults() {
mata mlib create lcmp, dir("`c(sysdir_plus)'l") replace
mata mlib add lcmp *(), dir("`c(sysdir_plus)'l")
mata mlib index
end
end
Binary file modified lcmp.mlib
Binary file not shown.
2 changes: 1 addition & 1 deletion unit tests.do
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set more off
set rmsg off
set trace off
set linesize 200
cap set processors 8
cap set processors 6

timer clear
timer on 1
Expand Down
8 changes: 3 additions & 5 deletions unit tests.log
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fem_work |
-------------+----------------------------------------------------------------
/lnsig_1 | .2849607 .0316228 9.01 0.000 .222981 .3469403
/lnsig_2 | -.183551 .5726942 -0.32 0.749 -1.306011 .938909
/atanhrho_12 | -1.507716 .6323635 -2.38 0.017 -2.747126 -.2683068
/atanhrho_12 | -1.507716 .6323634 -2.38 0.017 -2.747126 -.2683068
-------------+----------------------------------------------------------------
sig_1 | 1.32971 .0420492 1.249797 1.414732
sig_2 | .8323094 .4766588 .2708985 2.55719
Expand Down Expand Up @@ -1310,8 +1310,7 @@ security |
. use class10, clear
(Class of 2010 profile)

. cmp (graduate = program#(c.income roommate c.hsgpa) program income roommate hsgpa) (program = i.campus i.scholar income) (hsgpa = income i.hsc
> omp), vce(robust) ind(4 4 1) qui nolr
. cmp (graduate = program#(c.income roommate c.hsgpa) program income roommate hsgpa) (program = i.campus i.scholar income) (hsgpa = income i.hscomp), vce(robust) ind(4 4 1) qui nolr

Fitting individual models as starting point for full model fit.

Expand Down Expand Up @@ -2295,8 +2294,7 @@ Level: Observations |

. gen byte goodhlth = health > 3

. cmp (goodhlth = insured#c.(exercise grade) exercise grade insured || personid:) (insured = grade i.workschool || personid:), ind($cmp_probit $
> cmp_probit) intp(7) nolr
. cmp (goodhlth = insured#c.(exercise grade) exercise grade insured || personid:) (insured = grade i.workschool || personid:), ind($cmp_probit $cmp_probit) intp(7) nolr

For quadrature, defaulting to technique(bhhh) for speed.

Expand Down

0 comments on commit 0ab886b

Please sign in to comment.