Skip to content

Commit

Permalink
Fix crash in WRE with non-congruent FE & granular but not purerobust …
Browse files Browse the repository at this point in the history
…error clustering
  • Loading branch information
droodman committed Jul 2, 2023
1 parent aeb77fe commit 2209387
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WildBootTests"
uuid = "65c2e505-86ba-4c19-93f1-95506c1443d5"
authors = ["droodman <[email protected]>"]
version = "0.9.8"
version = "0.9.9"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
12 changes: 4 additions & 8 deletions src/WRE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,7 @@ function Filling!(o::StrBootTest{T}, dest::AbstractMatrix{T}, i::Int64, β̈s::A

t✻!(S✻UMZperpg, view(o.Repl.Zperp,S,:), o.S✻UZperpinvZperpZperpv); S✻UMZperpg .-= view(o.DGP.u⃛₁, S) .* view(o.v, view(o.ID✻, S),:)
if o.NFE>0 && !o.FEboot # CT_(*,FE) (U ̈_(∥j) ) (S_FE S_FE^' )^(-1) S_FE
@tturbo for r S # S✻UMZperpg .+= view(o.invFEwtCT✻FEUv, view(o._FEID,S), :)
_r = o._FEID[S[r]]
@tturbo for (r,_r) enumerate(o._FEID[S]) # S✻UMZperpg .+= view(o.invFEwtCT✻FEUv, view(o._FEID,S), :)
for c indices((S✻UMZperpg, o.invFEwtCT✻FEUv),2)
S✻UMZperpg[r,c] += o.invFEwtCT✻FEUv[_r,c]
end
Expand Down Expand Up @@ -566,13 +565,11 @@ function Filling!(o::StrBootTest{T}, dest::AbstractMatrix{T}, i::Int64, β̈s::A
end
end

# dest[g:g,:] .+= o.PXY✻ .* (o.S✻UMZperp .- o.Z̄[g,j] .* _β̈ )
@tturbo for c indices((dest, o.PXY✻, _β̈ , o.S✻UMZperp), 2)
@tturbo for c indices((dest, o.PXY✻, _β̈ , o.S✻UMZperp), 2) # dest[g:g,:] .+= o.PXY✻ .* (o.S✻UMZperp .- o.Z̄[g,j] .* _β̈ )
dest[g,c] += o.PXY✻[c] * (o.S✻UMZperp[c] - o.Z̄[g,j] * _β̈[c])
end
else
# dest[g:g,:] .-= o.Z̄[g,j] .* o.PXY✻ .* _β̈
@tturbo for c indices((dest, o.PXY✻, _β̈ ), 2)
@tturbo for c indices((dest, o.PXY✻, _β̈ ), 2) # dest[g:g,:] .-= o.Z̄[g,j] .* o.PXY✻ .* _β̈
dest[g,c] -= o.Z̄[g,j] * o.PXY✻[c] * _β̈[c]
end
end
Expand All @@ -596,8 +593,7 @@ function Filling!(o::StrBootTest{T}, dest::AbstractMatrix{T}, i::Int64, β̈s::A
t✻minus!(S✻UMZperpg, view(o.Z̄,S,j), _β̈ )

if o.NFE>0 && !o.FEboot # CT_(*,FE) (U ̈_(∥j) ) (S_FE S_FE^' )^(-1) S_FE
@tturbo for r S # S✻UMZperpg .+= view(o.invFEwtCT✻FEUv, view(o._FEID,S), :)
_r = o._FEID[S[r]]
@tturbo for (r,_r) enumerate(o._FEID[S]) # S✻UMZperpg .+= view(o.invFEwtCT✻FEUv, view(o._FEID,S), :)
for c indices((S✻UMZperpg, o.invFEwtCT✻FEUv),2)
S✻UMZperpg[r,c] += o.invFEwtCT✻FEUv[_r,c]
end
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ open("unittests.log", "w") do log # use Github Desktop to detect changes in out

df = DataFrame(load("nlsw88.dta"))[:,[:wage; :tenure; :ttl_exp; :collgrad; :industry]]
dropmissing!(df)
desc = describe(df, :eltype)
f = @formula(wage ~ 1 + tenure + ttl_exp + collgrad)
f = apply_schema(f, schema(f, df))
resp, predexog = modelcols(f, df)
Expand All @@ -129,7 +128,7 @@ open("unittests.log", "w") do log # use Github Desktop to detect changes in out
test = wildboottest([0 1 0 0], [0]; R1=[0 0 1 0], r1=[.2], resp, predexog, clustid=[collect(1:1000); collect(1:1217)], reps=9999, rng=StableRNG(1231)) # granular but not pure robust
println(log, test)

test = wildboottest([0 1 0 0], [0]; resp, predexog, clustid=[collect(1:1000); collect(1:1217)], feid=df.industry, reps=9999, rng=StableRNG(1231))
test = wildboottest([1 0 0], [0]; resp, predexog=predexog[:,2:end], clustid=[collect(1:1000); collect(1:1217)], feid=df.industry, reps=9999, rng=StableRNG(1231))
println(log, test)

df = DataFrame(load("nlsw88.dta"))
Expand Down
3 changes: 1 addition & 2 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ open("unittests.log", "w") do log # use Github Desktop to detect changes in out

df = DataFrame(load("nlsw88.dta"))[:,[:wage; :tenure; :ttl_exp; :collgrad; :industry]]
dropmissing!(df)
desc = describe(df, :eltype)
f = @formula(wage ~ 1 + tenure + ttl_exp + collgrad)
f = apply_schema(f, schema(f, df))
resp, predexog = modelcols(f, df)
Expand All @@ -129,7 +128,7 @@ open("unittests.log", "w") do log # use Github Desktop to detect changes in out
test = wildboottest([0 1 0 0], [0]; R1=[0 0 1 0], r1=[.2], resp, predexog, clustid=[collect(1:1000); collect(1:1217)], reps=9999, rng=StableRNG(1231)) # granular but not pure robust
println(log, test)

test = wildboottest([0 1 0 0], [0]; resp, predexog, clustid=[collect(1:1000); collect(1:1217)], feid=df.industry, reps=9999, rng=StableRNG(1231))
test = wildboottest([1 0 0], [0]; resp, predexog=predexog[:,2:end], clustid=[collect(1:1000); collect(1:1217)], feid=df.industry, reps=9999, rng=StableRNG(1231))
println(log, test)

df = DataFrame(load("nlsw88.dta"))
Expand Down
16 changes: 8 additions & 8 deletions test/unittests.log
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ p = 0.0723

boottest post_self=.04, weight(mammen) reps(9999) noci
t(7) = 2.0194
p = 0.1788
p = 0.1040


boottest post_self=.04, weight(mammen) reps(9999) boottype(score)
t(7) = 1.8479
p = 0.0903
CI = [0.0335 0.08018]
CI = [0.03008 0.03173; 0.0335 0.08018]


boottest post_self=.04, reps(9999) jk
Expand Down Expand Up @@ -201,9 +201,9 @@ t(1216) = 3.3434
p = 0.0007
CI = [0.02699 0.1033]

t(1216) = 0.7518
p = 0.4657
CI = [-0.02853 0.06396]
t(1216) = 0.7606
p = 0.4655
CI = [-0.02845 0.06413]


ivregress 2sls wage ttl_exp collgrad (tenure = union), cluster(industry)
Expand Down Expand Up @@ -336,7 +336,7 @@ p = 0.0080

boottest tenure, nograph bootcluster(collgrad) cluster(collgrad industry) weight(webb) reps(9999)
z = 3.9420
p = 0.2033
p = 0.2153
CI = [-Inf Inf]


Expand Down Expand Up @@ -377,7 +377,7 @@ ivreghdfe wage ttl_exp collgrad tenure (occupation = union married) [aw=hours] i
boottest tenure
t(11) = 2.0244
p = 0.2452
CI = [-2.499 -0.9603; -0.1759 2.585]
CI = [-2.499 -0.9603; -0.1753 2.585]

boottest tenure, jk
t(11) = 0.6068
Expand All @@ -396,7 +396,7 @@ CI = [-0.4551 0.8325]
boottest tenure | _b[collgrad] = 0
t(11) = -2.0001
p = 0.3544
CI = [-0.5463 -0.0707; -0.05762 Inf]
CI = [-0.5463 Inf]

t(11) = -2.0001
p = 0.3544
Expand Down

2 comments on commit 2209387

@droodman
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/86689

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.9 -m "<description of version>" 22093873979bca04780fff2b03f1bf38248bd01f
git push origin v0.9.9

Please sign in to comment.