Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ycroissant/plm
Browse files Browse the repository at this point in the history
# Conflicts:
#	R/est_gmm.R
  • Loading branch information
tappek committed Jan 4, 2025
2 parents 6f27b0d + 8d9993a commit c796596
Show file tree
Hide file tree
Showing 11 changed files with 957 additions and 403 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: plm
Version: 2.6-9999
Date: 2024-04-04
Date: 2025-01-02
Title: Linear Models for Panel Data
Authors@R: c(person(given = "Yves", family = "Croissant", role = c("aut"), email = "[email protected]"),
person(given = "Giovanni", family = "Millo", role = c("aut"), email = "[email protected]"),
Expand Down
11 changes: 7 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ subtitle: plm - Linear Models for Panel Data - A set of estimators and tests for
# 2.6-9999 development version, changes since 2.6-4

### Fixes:
* `pgmm`:
* for one-step GMM models: usual (non-robust) covariance matrix/standard errors fixed.
* argument `fsm` can now be set to influence the first step's weighing matrix.
* `vcovXX`: FD models with only one observation per group prior to
first-differencing errored ([#58](https://github.com/ycroissant/plm/issues/58)).
* `pggls`: FD models errored with the data constellation as described for `vcovXX`.
first-differencing errored ([#58](https://github.com/ycroissant/plm/issues/58)).
* `pggls`: FD models errored with the data constellation as described above for `vcovXX`.
* `is.pdata.frame` (non-exported helper function): fix part of the check if object
does not have an index.
* Vignette A: fixed description of `pgmm`'s `effect` argument.
does not have an index.
* Vignette A: improved description of `pgmm`'s `effect` argument.


***
Expand Down
6 changes: 6 additions & 0 deletions R/tool_argvalues.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ oneof <- function(x){

plm.arg <- c("formula", "data", "subset", "weights", "na.action", "effect", "model",
"instruments", "random.method", "inst.method", "index")

pgmm.fsm.list <- c(I = "I",
G = "G",
GI = "GI",
full = "full")

38 changes: 16 additions & 22 deletions R/tool_vcovG.R
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ vcovHC.pgmm <- function(x, ...) {
transformation <- describe(x, "transformation")
A1 <- x$A1
A2 <- x$A2
B1 <- x$B1

if(transformation == "ld") {
## yX <- lapply(x$model,function(x) rbind(diff(x),x))
Expand All @@ -1237,51 +1238,44 @@ vcovHC.pgmm <- function(x, ...) {
yX <- x$model
residuals <- x$residuals
}

minevA2 <- min(abs(Re(eigen(A2)$values)))
eps <- 1E-9

SA2 <- if(minevA2 < eps){
warning("a general inverse is used")
ginv(A2)
} else solve(A2)


WX <- Reduce("+", mapply(function(w, y) crossprod(w, y[ , -1L, drop = FALSE]), x$W, yX, SIMPLIFY = FALSE))

# robust vcov for one-step GMM, see Roodman (2009), formula (15)
vcovr1s <- B1 %*% (t(WX) %*% A1 %*% SA2 %*% A1 %*% WX) %*% B1

if(model == "twosteps") {
coef1s <- x$coefficients[[1L]]
res1s <- lapply(yX, function(x) x[ , 1L] - crossprod(t(x[ , -1L, drop = FALSE]), coef1s))
K <- ncol(yX[[1L]])
D <- c()
WX <- Reduce("+",
mapply(function(x, y) crossprod(x, y[ , -1L, drop = FALSE]), x$W, yX, SIMPLIFY = FALSE))
We <- Reduce("+", mapply(function(x, y) crossprod(x, y), x$W, residuals, SIMPLIFY = FALSE))
B1 <- solve(t(WX) %*% A1 %*% WX)
vcov1s <- B1 %*% (t(WX) %*% A1 %*% SA2 %*% A1 %*% WX) %*% B1 # robust vcov for one-step model
for (k in 2:K) {
exk <- mapply(
function(x, y){
exk <- mapply(function(x, y){
z <- crossprod(t(x[ , k, drop = FALSE]), t(y))
return(- z - t(z))
},
yX, res1s, SIMPLIFY = FALSE)
wexkw <- Reduce("+",
mapply(
function(x, y)
crossprod(x, crossprod(y, x)),
x$W, exk, SIMPLIFY = FALSE))

wexkw <- Reduce("+", mapply(function(x, y)
crossprod(x, crossprod(y, x)),
x$W, exk, SIMPLIFY = FALSE))
B2 <- vcov(x)
Dk <- -B2 %*% t(WX) %*% A2 %*% wexkw %*% A2 %*% We
D <- cbind(D, Dk)
}
vcovr <- B2 + crossprod(t(D), B2) + t(crossprod(t(D), B2)) + D %*% vcov1s %*% t(D) # robust vcov for twosteps model, Roodman (2019) form. (18)
}
else {
# model = "onestep"
res1s <- lapply(yX, function(z) z[ , 1L] - crossprod(t(z[ , -1L, drop = FALSE]), x$coefficients))
K <- ncol(yX[[1L]])
WX <- Reduce("+", mapply(function(z, y) crossprod(z[ , -1L, drop = FALSE], y), yX, x$W, SIMPLIFY = FALSE))
B1 <- vcov(x)
vcovr <- B1 %*% (WX %*% A1 %*% SA2 %*% A1 %*% t(WX)) %*% B1 # robust vcov onestep model, Roodman (2019) form. (15)
# robust vcov for twosteps GMM model, Roodman (2019) form. (18)
vcovr2s <- B2 + crossprod(t(D), B2) + t(crossprod(t(D), B2)) + D %*% vcovr1s %*% t(D)
}
vcovr
if(model == "twosteps") vcovr2s else vcovr1s
}


Expand Down
2 changes: 1 addition & 1 deletion inst/tests/test_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ z1 <- pgmm(log(emp) ~ log(wage) + log(capital) + log(output),
gmm.inst = ~log(emp), lag.gmm = list(c(2,99)))
summary(z1, robust = FALSE)

## Blundell and Bond (1998) table 4 (cf DPD for OX p. 12 col. 4)
## Blundell and Bond (1998) table 4 (cf. DPD for OX p. 12 col. 4)
z2 <- pgmm(dynformula(log(emp) ~ log(wage) + log(capital), list(1,1,1)),
data = EmplUK, effect = "twoways", model = "onestep",
gmm.inst = ~log(emp) + log(wage) + log(capital),
Expand Down
14 changes: 7 additions & 7 deletions inst/tests/test_misc.Rout.save
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

R version 4.4.1 (2024-06-14 ucrt) -- "Race for Your Life"
R version 4.4.2 (2024-10-31 ucrt) -- "Pile of Leaves"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64

Expand Down Expand Up @@ -1493,8 +1493,8 @@ lag(log(capital), 0:1)1 -0.424393 0.058479 -7.2572 3.952e-13 ***
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Sargan test: chisq(100) = 118.763 (p-value = 0.097096)
Autocorrelation test (1): normal = -4.808434 (p-value = 1.5212e-06)
Autocorrelation test (2): normal = -0.2800133 (p-value = 0.77947)
Autocorrelation test (1): normal = -5.519159 (p-value = 3.4063e-08)
Autocorrelation test (2): normal = -0.2524777 (p-value = 0.80067)
Wald test for coefficients: chisq(5) = 11174.82 (p-value = < 2.22e-16)
Wald test for time dummies: chisq(7) = 14.71138 (p-value = 0.039882)
>
Expand Down Expand Up @@ -1542,7 +1542,7 @@ Autocorrelation test (2): normal = -0.3325401 (p-value = 0.73948)
Wald test for coefficients: chisq(7) = 371.9877 (p-value = < 2.22e-16)
Wald test for time dummies: chisq(6) = 26.9045 (p-value = 0.0001509)
>
> ## Blundell and Bond (1998) table 4 (cf DPD for OX p. 12 col. 4)
> ## Blundell and Bond (1998) table 4 (cf. DPD for OX p. 12 col. 4)
> z2 <- pgmm(dynformula(log(emp) ~ log(wage) + log(capital), list(1,1,1)),
+ data = EmplUK, effect = "twoways", model = "onestep",
+ gmm.inst = ~log(emp) + log(wage) + log(capital),
Expand Down Expand Up @@ -1579,8 +1579,8 @@ lag(log(capital), 1) -0.424393 0.058479 -7.2572 3.952e-13 ***
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Sargan test: chisq(100) = 118.763 (p-value = 0.097096)
Autocorrelation test (1): normal = -4.808434 (p-value = 1.5212e-06)
Autocorrelation test (2): normal = -0.2800133 (p-value = 0.77947)
Autocorrelation test (1): normal = -5.519159 (p-value = 3.4063e-08)
Autocorrelation test (2): normal = -0.2524777 (p-value = 0.80067)
Wald test for coefficients: chisq(5) = 11174.82 (p-value = < 2.22e-16)
Wald test for time dummies: chisq(7) = 14.71138 (p-value = 0.039882)
>
Expand Down Expand Up @@ -1891,4 +1891,4 @@ Coefficients:
>
> proc.time()
user system elapsed
10.04 0.75 10.76
9.45 0.90 10.32
Loading

0 comments on commit c796596

Please sign in to comment.