Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IV models with a single regressor don't work with fancy covariance matrices #4

Closed
tcovert opened this issue Mar 18, 2021 · 5 comments
Closed
Labels
bug Something isn't working multiple topics issue is about multiple topics in one GitHub issue
Milestone

Comments

@tcovert
Copy link

tcovert commented Mar 18, 2021

Consider a (modified) example from the help:

zz <- plm(log(gsp) ~ log(pcap) | log(pc) + log(emp),
	     data = Produc, index = c("state","year"),
	     model = "within")

When you type summary(zz) you get:

> summary(zz)
Oneway (individual) effect Within Model
Instrumental variable estimation

Call:
plm(formula = log(gsp) ~ log(pcap) | log(pc) + log(emp), data = Produc, 
    model = "within", index = c("state", "year"))

Balanced Panel: n = 48, T = 17, N = 816

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.3779409 -0.0561652 -0.0055046  0.0440775  0.4590412 

Coefficients:
          Estimate Std. Error z-value  Pr(>|z|)    
log(pcap) 1.528846   0.035191  43.444 < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    18.941
Residual Sum of Squares: 7.0211
R-Squared:      0.69103
Adj. R-Squared: 0.67169
Chisq: 1887.37 on 1 DF, p-value: < 2.22e-16

Now, what about Driscoll-Kraay standard errors?

> summary(zz, vcov = vcovSCC)
Error in demX[tind[[i]], , drop = FALSE] : incorrect number of dimensions

I believe the problem is in the definition of vcovG, where the variable demX is defined for models with instrumental variables. If the model matrix has just one column (as in the above example), demX is a column vector, not a matrix. I've found that if you wrap that line in an as.matrix everything else works.

@tappek
Copy link
Collaborator

tappek commented Mar 18, 2021

Thank you for reporting with a reproducible example and the analysis!
I will commit a fix to our development repository later this day.

@tappek
Copy link
Collaborator

tappek commented Mar 18, 2021

This is fixed in revision #1125 in our development repository (currently building): https://r-forge.r-project.org/R/?group_id=406

It affected all vcovXX functions making use of vcovG (vcovHC, vcovNW, vcovDC, vcovSCC) as well as the vcovBK which does not make use of vcovG.

@chuqingjin
Copy link

I found a similar issue in within_intercept, which also seems to not support models with one covariate.

Here is a reproducible example:

data("Produc", package = "plm")  
zz <- plm(log(gsp) ~ log(pcap), data = Produc, index = c("state","year"), model = "within")  
inter <- within_intercept(zz)

The error message is
Error in colMeans(M) : 'x' must be an array of at least two dimensions.

Again, wrapping M with as.matrix seems to fix the issue.

@tappek
Copy link
Collaborator

tappek commented Jun 25, 2021

Thank you for reporting! This is similar but code-wise independent.

Fixed by adding one of the famous drop = FALSE addition to matrix subsetting in within_intercept in rev. 1143 on R-Forge.

@tappek tappek closed this as completed Jun 26, 2021
@tappek tappek added the bug Something isn't working label Jun 26, 2021
@tappek tappek added this to the plm 2.4-2 milestone Aug 26, 2021
@tappek tappek added the multiple topics issue is about multiple topics in one GitHub issue label Aug 31, 2021
@tappek
Copy link
Collaborator

tappek commented Sep 21, 2021

plm version 2.4-2 now on CRAN (2021-09-21) containing these fixes

tappek pushed a commit that referenced this issue Sep 26, 2021
tappek pushed a commit that referenced this issue Sep 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working multiple topics issue is about multiple topics in one GitHub issue
Projects
None yet
Development

No branches or pull requests

3 participants