Repository navigation
Fix ranktest: build b_qq from the k-th right singular vector - #28
Merged
eloualiche merged 1 commit intoOct 30, 2026
Merged
eloualiche merged 1 commit into
eloualiche merged 1 commit into
Conversation
b_qq used vt[1:k, k], the k-th column of Vt, i.e. the k-th row of V. Kleibergen and Paap (2006, p. 102) and Stata's ranktest (m_svd: bq = v22h*luqrinv(v22')*(v12 \ v22)') use the k-th right singular vector, the k-th column of V = vt[k, 1:k]. With more than one endogenous regressor, the KP rk statistic (and FixedEffectModels' F_kp) was therefore wrong and depended on the order of the endogenous variables. With one endogenous regressor vt is 1x1 and nothing changes. Tests: with simple covariance the statistic equals n * s_k^2 (smallest singular value of theta), and it is invariant to permuting the endogenous variables (simple and robust). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
@matthieugomez? |
Member
|
LGTM! |
This was referenced Oct 30, 2026
Member
|
Thanks @paul-huebner |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
In
ranktest!,b_qqis built fromvt[1:k, k]:vtisV', sovt[1:k, k]is the k-th column ofV', which is the k-th row ofV. Kleibergen and Paap (2006, p. 102) buildB_q⊥from[V12; V22], the last k − q columns ofV. For q = k − 1 that is the k-th column ofV, the right singular vector of the smallest singular value, which isvt[k, 1:k].Stata's
ranktestdoes the same thing. The header ofranktest.jlsays this file corresponds to it. Inranktest.ado(v2.0.04),m_svdis called withkpvt', which isV, and computesIn Mata,
(v12 \ v22)stacks the two blocks vertically, so it is the k-th column ofV. Thea_qqside already matches Stata; onlyb_qqis transposed.Effect: with one endogenous regressor,
vtis 1×1 and nothing changes. With two or more, the KP rk statistic is wrong wheneverVis not symmetric. This includes FixedEffectModels'F_kp.simple()it understates the statistic. With robust or clustered covariance it can go either way.Example (FixedEffectModels v2.1.0)
F_kpsimple, Vcov 0.8.3F_kprobust, Vcov 0.8.3F_kpsimple, this PRF_kprobust, this PRWith the fix, the homoskedastic statistic equals
n * s_k^2, wheres_kis the smallest singular value oftheta. This is the Cragg–Donald form that KP reduces to under i.i.d. errors.Changes
src/ranktest.jl:vt[1:k, k]'becomesvt[k, 1:k]', in both branches of theb_qqline, plus a comment.test/estimators.jl: new tests for k = l = 3 and for k = 2, l = 4. All six fail onmainand pass with the fix. They check that:simple(), the statistic equalsn * s_k^2;simple()and underrobust().🤖 Generated with Claude Code