Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit bd17334

Browse files
committed
Change argument name vcov to vce
1 parent 720f3a5 commit bd17334

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

src/InteractionWeightedDIDs.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import DiffinDiffsBase: required, default, transformed, combinedargs, _getsubcol
2424
valid_didargs, result
2525
import FixedEffectModels: has_fe
2626

27-
# Handle naming conflicts
28-
const getvcov = vcov
29-
3027
export Vcov,
3128
fe
3229

src/procedures.jl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
"""
22
checkvcov!(args...)
33
4-
Exclude rows that are invalid for `vcov`.
4+
Exclude rows that are invalid for variance-covariance estimator.
55
See also [`CheckVcov`](@ref).
66
"""
77
checkvcov!(data, esample::BitVector,
8-
vcov::Union{Vcov.SimpleCovariance, Vcov.RobustCovariance}) = NamedTuple(), false
8+
vce::Union{Vcov.SimpleCovariance, Vcov.RobustCovariance}) = NamedTuple(), false
99

10-
function checkvcov!(data, esample::BitVector, vcov::Vcov.ClusterCovariance)
11-
esample .&= Vcov.completecases(data, vcov)
10+
function checkvcov!(data, esample::BitVector, vce::Vcov.ClusterCovariance)
11+
esample .&= Vcov.completecases(data, vce)
1212
return (esample=esample,), false
1313
end
1414

1515
"""
1616
CheckVcov <: StatsStep
1717
18-
Call [`InteractionWeightedDIDs.checkvcov!`](@ref) to exclude invalid rows for
19-
`Vcov.CovarianceEstimator`.
18+
Call [`InteractionWeightedDIDs.checkvcov!`](@ref) to
19+
exclude rows that are invalid for variance-covariance estimator.
2020
"""
2121
const CheckVcov = StatsStep{:CheckVcov, typeof(checkvcov!)}
2222

2323
required(::CheckVcov) = (:data, :esample)
24-
default(::CheckVcov) = (vcov=Vcov.robust(),)
24+
default(::CheckVcov) = (vce=Vcov.robust(),)
2525

2626
"""
2727
checkfes!(args...)
@@ -336,24 +336,24 @@ const SolveLeastSquares = StatsStep{:SolveLeastSquares, typeof(solveleastsquares
336336
required(::SolveLeastSquares) = (:tr, :yterm, :xterms, :yxterms, :yxcols, :treatcols,
337337
:has_fe_intercept)
338338

339-
function _vcov(data, esample::BitVector,
340-
vcov::Union{Vcov.SimpleCovariance,Vcov.RobustCovariance}, fes::Vector{FixedEffect})
339+
function _vce(data, esample::BitVector,
340+
vce::Union{Vcov.SimpleCovariance,Vcov.RobustCovariance}, fes::Vector{FixedEffect})
341341
dof_absorb = 0
342342
for fe in fes
343343
dof_absorb += nunique(fe)
344344
end
345-
return vcov, dof_absorb
345+
return vce, dof_absorb
346346
end
347347

348-
function _vcov(data, esample::BitVector, vcov::Vcov.ClusterCovariance,
348+
function _vce(data, esample::BitVector, vce::Vcov.ClusterCovariance,
349349
fes::Vector{FixedEffect})
350-
cludata = _getsubcolumns(data, vcov.clusters, esample)
351-
concrete_vcov = Vcov.materialize(cludata, vcov)
350+
cludata = _getsubcolumns(data, vce.clusters, esample)
351+
concrete_vce = Vcov.materialize(cludata, vce)
352352
dof_absorb = 0
353353
for fe in fes
354-
any(c->isnested(fe, c.refs), concrete_vcov.clusters) && (dof_absorb += 1)
354+
any(c->isnested(fe, c.refs), concrete_vce.clusters) && (dof_absorb += 1)
355355
end
356-
return concrete_vcov, dof_absorb
356+
return concrete_vce, dof_absorb
357357
end
358358

359359
"""
@@ -362,19 +362,19 @@ end
362362
Estimate variance-covariance matrix and F-statistic.
363363
See also [`EstVcov`](@ref).
364364
"""
365-
function estvcov(data, esample::BitVector, vcov::CovarianceEstimator, coef::Vector,
365+
function estvcov(data, esample::BitVector, vce::CovarianceEstimator, coef::Vector,
366366
X::Matrix, crossx::Factorization, residuals::Vector,
367367
xterms::Terms, fes::Vector{FixedEffect}, has_fe_intercept::Bool)
368-
concrete_vcov, dof_absorb = _vcov(data, esample, vcov, fes)
368+
concrete_vce, dof_absorb = _vce(data, esample, vce, fes)
369369
dof_resid = max(1, sum(esample) - size(X,2) - dof_absorb)
370-
vcov_data = Vcov.VcovData(X, crossx, residuals, dof_resid)
371-
vcov_mat = getvcov(vcov_data, concrete_vcov)
370+
vce_data = Vcov.VcovData(X, crossx, residuals, dof_resid)
371+
vcov_mat = vcov(vce_data, concrete_vce)
372372

373373
# Fstat assumes the last coef is intercept if having any intercept
374374
has_intercept = !isempty(xterms) && isintercept(xterms[end])
375375
F = Fstat(coef, vcov_mat, has_intercept)
376376
has_intercept = has_intercept || has_fe_intercept
377-
df_F = max(1, Vcov.df_FStat(vcov_data, concrete_vcov, has_intercept))
377+
df_F = max(1, Vcov.df_FStat(vce_data, concrete_vce, has_intercept))
378378
p = fdistccdf(max(length(coef) - has_intercept, 1), df_F, F)
379379

380380
return (vcov_mat=vcov_mat, dof_resid=dof_resid, F=F, p=p), true
@@ -390,5 +390,5 @@ may be shared across multiple specifications.
390390
"""
391391
const EstVcov = StatsStep{:EstVcov, typeof(estvcov)}
392392

393-
required(::EstVcov) = (:data, :esample, :vcov, :coef, :X, :crossx, :residuals, :xterms,
393+
required(::EstVcov) = (:data, :esample, :vce, :coef, :X, :crossx, :residuals, :xterms,
394394
:fes, :has_fe_intercept)

test/procedures.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@testset "CheckVcov" begin
22
hrs = exampledata("hrs")
3-
nt = (data=hrs, esample=trues(size(hrs,1)), vcov=Vcov.robust())
3+
nt = (data=hrs, esample=trues(size(hrs,1)), vce=Vcov.robust())
44
@test checkvcov!(nt...) == (NamedTuple(), false)
5-
nt = merge(nt, (vcov=Vcov.cluster(:hhidpn),))
5+
nt = merge(nt, (vce=Vcov.cluster(:hhidpn),))
66
@test checkvcov!(nt...) == ((esample=trues(size(hrs,1)),), false)
77

88
@test CheckVcov()((data=hrs, esample=trues(size(hrs,1)))) ==
@@ -272,7 +272,7 @@ end
272272
crossx = cholesky!(Symmetric(X'X))
273273
coef = crossx \ (X'y)
274274
residuals = y - X * coef
275-
nt = (data=hrs, esample=trues(nobs), vcov=Vcov.simple(), coef=coef,
275+
nt = (data=hrs, esample=trues(nobs), vce=Vcov.simple(), coef=coef,
276276
X=X, crossx=crossx, residuals=residuals, xterms=(term(1),), fes=FixedEffect[],
277277
has_fe_intercept=false)
278278
ret, share = estvcov(nt...)
@@ -287,7 +287,7 @@ end
287287
@test ret.dof_resid == nobs - 3
288288
@test ret.F 10.68532285556941 atol=1e-6
289289

290-
nt = merge(nt, (vcov=Vcov.robust(), fes=FixedEffect[]))
290+
nt = merge(nt, (vce=Vcov.robust(), fes=FixedEffect[]))
291291
ret, share = estvcov(nt...)
292292
# Compare estimates with Stata
293293
# reg oop_spend col0 col1, r
@@ -300,7 +300,7 @@ end
300300
@test ret.dof_resid == nobs - 3
301301
@test ret.F 5.371847047691197 atol=1e-6
302302

303-
nt = merge(nt, (vcov=Vcov.cluster(:hhidpn),))
303+
nt = merge(nt, (vce=Vcov.cluster(:hhidpn),))
304304
ret, share = estvcov(nt...)
305305
# Compare estimates with Stata
306306
# reghdfe oop_spend col0 col1, noa clu(hhidpn)
@@ -321,7 +321,7 @@ end
321321
crossx = cholesky!(Symmetric(X'X))
322322
coef = crossx \ (X'y)
323323
residuals = y - X * coef
324-
nt = merge(nt, (vcov=Vcov.robust(), coef=coef, X=X, crossx=crossx, residuals=residuals, xterms=(), fes=fes, has_fe_intercept=true))
324+
nt = merge(nt, (vce=Vcov.robust(), coef=coef, X=X, crossx=crossx, residuals=residuals, xterms=(), fes=fes, has_fe_intercept=true))
325325
ret, share = estvcov(nt...)
326326
# Compare estimates with Stata
327327
# reghdfe oop_spend col0 col1, a(hhidpn) vce(robust)
@@ -332,7 +332,7 @@ end
332332
@test ret.dof_resid == nobs - nunique(fes[1]) - 2
333333
@test ret.F 7.559815337537517 atol=1e-6
334334

335-
nt = merge(nt, (vcov=Vcov.cluster(:hhidpn),))
335+
nt = merge(nt, (vce=Vcov.cluster(:hhidpn),))
336336
ret, share = estvcov(nt...)
337337
# Compare estimates with Stata
338338
# reghdfe oop_spend col0 col1, a(hhidpn) clu(hhidpn)

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const tests = [
2222
"did"
2323
]
2424

25-
printstyled("Running tests:\n", color=:blue)
25+
printstyled("Running tests:\n", color=:blue, bold=true)
2626

27-
for test in tests
27+
@time for test in tests
2828
include("$test.jl")
2929
println("\033[1m\033[32mPASSED\033[0m: $(test)")
3030
end

0 commit comments

Comments
 (0)