Skip to content

Commit a7f7e51

Browse files
committed
Fixed crash on boottest, margins after areg
1 parent 29b9df9 commit a7f7e51

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

boottest.ado

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
*! boottest 4.4.11 12 April 2024
2-
*! Copyright (C) 2015-24 David Roodman
1+
*! boottest 4.4.12 15 January 2025
2+
*! Copyright (C) 2015-25 David Roodman
33

44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -151,15 +151,25 @@ program define _boottest, rclass sortpreserve
151151
}
152152
153153
local margins = "`margins'" != ""
154-
if `margins' & `"`h0s'`h0'"' != "" {
155-
di as err "Include the {cmd:margins} option or state null hyptheses, but don't do both."
156-
exit 198
157-
}
158-
if `margins' & "`r(predict1_label)'" != "Linear prediction" {
159-
di as err _n "{cmd:margins} option only works with linear margins predictions such as average predictions after {cmd:regress}."
160-
exit 198
154+
if `margins' {
155+
if `"`h0s'`h0'"' != "" {
156+
di as err "Include the {cmd:margins} option or state null hyptheses, but don't do both."
157+
exit 198
158+
}
159+
if "`r(predict1_label)'" != "Linear prediction" {
160+
di as err _n "{cmd:margins} option only works with linear margins predictions such as average predictions after {cmd:regress}."
161+
exit 198
162+
}
163+
if strlen("`r(Jacobian)'") {
164+
tempname rJacobian
165+
mat `rJacobian' = r(Jacobian)
166+
}
167+
else {
168+
di as err "{cmd:margins} results not found."
169+
error 303
170+
}
161171
}
162-
172+
163173
if inlist("`e(cmd)'", "didregress", "xtdidregress") & `"`h0s'`h0'"' == "" local h0s r1vs0.`e(treatment)'
164174
165175
if `matsizegb'==1000000 local matsizegb .
@@ -396,25 +406,18 @@ program define _boottest, rclass sortpreserve
396406
local anythingh0 1
397407
}
398408
else if `margins' {
399-
if strlen("`r(Jacobian)'") {
400-
mata _boottestp = selectindex(rowsum(st_matrix("r(Jacobian)"):!=0)) // skip all-zero rows
401-
mata st_local("marginsnames", invtokens(st_matrixrowstripe("r(Jacobian)")[_boottestp,2]'))
402-
mata st_matrix("`marginsH0'", st_matrix("r(Jacobian)")[_boottestp,])
403-
mata st_local("N_h0s", strofreal(length(_boottestp)))
404-
if `N_h0s'==0 {
405-
di as err "No valid {cmd:margins} results not found."
406-
error 303
407-
}
408-
scalar `df' = 1 // always when working with margins results, df = 1 and constant term = 0
409-
mat `r' = 0
410-
411-
local 0 r(cmdline)
412-
marksample marginstouse, strok
413-
}
414-
else {
415-
di as err "{cmd:margins} results not found."
409+
mata _boottestp = selectindex(rowsum(st_matrix("`rJacobian'"):!=0)) // skip all-zero rows
410+
mata st_local("marginsnames", invtokens(st_matrixrowstripe("`rJacobian'")[_boottestp,2]'))
411+
mata st_matrix("`marginsH0'", st_matrix("`rJacobian'")[_boottestp,])
412+
mata st_local("N_h0s", strofreal(length(_boottestp)))
413+
if `N_h0s'==0 {
414+
di as err "No valid {cmd:margins} results not found."
416415
error 303
417416
}
417+
scalar `df' = 1 // always when working with margins results, df = 1 and constant term = 0
418+
mat `r' = 0
419+
420+
marksample marginstouse, strok
418421
}
419422
else {
420423
local N_h0s 1 // number of nulls
@@ -1105,6 +1108,7 @@ end
11051108

11061109

11071110
* Version history
1111+
* 4.4.12 Fixed crash on boottest, margins after areg
11081112
* 4.4.11 Change formula for bounds search start in ARubin to prevent missings. Updated jl usage.
11091113
* 4.4.10 Fixed crash after latest versions of *reghdfe*
11101114
* 4.4.9 Added jl SetEnv call to create private Julia package environment

0 commit comments

Comments
 (0)