Richard Hardy
2024-Apr-23 09:16 UTC
[R] System GMM yields identical results for any weighting matrix
A copy of this question can be found on Cross Validated: https://stats.stackexchange.com/questions/645362 I am estimating a system of seemingly unrelated regressions (SUR) in R. Each of the equations has one unique regressor and one common regressor. I am using `gmm::sysGmm` and am experimenting with different weighting matrices. I get the same results (point estimates, standard errors and anything else that I can see (**except** for the value of the $J$-test) regardless of the weighting matrix. I do not think this is correct. The phenomenon persists regardless of what type of covariance matrix estimator I use: `MDS`, `CondHom` or `HAC`. It also persists regardless of whether I use unrestricted estimation or restrict the coefficients on one of the variables (the common regressor) to be equal across equations. **Question:** Why does system GMM via `gmm::sysGmm` yield identical results for any weighting matrix? How can I make it yield proper results that vary with the weighting matrix (if that makes sense and I am not mistaken, of course)? ------------------------------ R code for a reproducible example library(gmm) library(systemfit) # Generate and prepare the data n <- 1000 # sample size m <- 100 # length of the "second part" of the sample N <- 3 # number of equations set.seed(321); x <- matrix(rnorm(n*N),ncol=N); colnames(x) <- paste0("x",1:N) # generate regressors dummy <- c( rep(0,n-m), rep(1,m) ) # generate a common regressor x <- cbind(x,dummy) # include the common regressor with the rest of the regressors set.seed(123); y <- matrix(rnorm(n*N),ncol=N); colnames(y) <- paste0("y",1:N) # a placeholder for dependent variables for(i in 1:N){ y[,i] <- i + sqrt(i)*x[,i] - i*dummy + y[,i]*15*sqrt(i) # y[,i] is a linear function of x[,i] and dummy, # plus an error term with equation-specific variance } data1 <- as.data.frame(cbind(y,x)) # create a data frame of all data (y and x) # Create the model equations and moment conditions ES_g = ES_h <- list() # ES ~ equation system for(i in 1:N){ ES_g[[i]] <- as.formula(assign(paste0("eq",i), value=paste0("y",i," ~ x",i," + dummy"))) # define linear equations of SUR ES_h[[i]] <- as.formula(assign(paste0("eq",i), value=paste0( "~ x",i," + dummy"))) # define the moment conditions for GMM } # Estimate a WLS-type weighting matrix to use as a user-specified weighting matrix in GMM m0 <- systemfit(formula=ES_g, method="OLS", data=data1) OLSmat <- diag(diag(m0$residCov)); Wmat <- solve(OLSmat) # Choose the type of covariance matrix in GMM vc1 <- "MDS" vc1 <- "CondHom" vc1 <- "HAC" #vc1 <- "TrueFixed" # Choose between restricted and unrestricted estimation cec1=NULL # unrestricted cec1=3 # restrict the coefficient on the dummy to be equal across equations # Estimate the model with `sysGmm` using different weighting matrices: identity, "optimal" and manually specified m1a <- sysGmm(g=ES_g, h=ES_h, wmatrix="ident" , weightsMatrix=NULL, vcov=vc1, crossEquConst=cec1, data=data1); summary(m1a) m1b <- sysGmm(g=ES_g, h=ES_h, wmatrix="optimal", weightsMatrix=NULL, vcov=vc1, crossEquConst=cec1, data=data1); summary(m1b) m1c <- sysGmm(g=ES_g, h=ES_h, weightsMatrix=Wmat, vcov=vc1, crossEquConst=cec1, data=data1); summary(m1c) ------------------------------ R session info: R version 4.3.3 (2024-02-29 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045) Matrix products: default locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 [3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C [5] LC_TIME=English_United States.utf8 time zone: Europe/Berlin tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] systemfit_1.1-30 lmtest_0.9-40 zoo_1.8-12 car_3.1-2 carData_3.0-5 Matrix_1.6-1 [7] gmm_1.8 sandwich_3.0-2 loaded via a namespace (and not attached): [1] MASS_7.3-60.0.1 compiler_4.3.3 tools_4.3.3 abind_1.4-5 rstudioapi_0.15.0 grid_4.3.3 [7] lattice_0.22-5 ------------------------------ Kind regards, Richard [[alternative HTML version deleted]]
Bert Gunter
2024-Apr-23 18:45 UTC
[R] System GMM yields identical results for any weighting matrix
Generally speaking, this sort of detailed statistical question about a speccial package in R does not get a reply on this general R programming help list. Instead, I suggest you either email the maintainer (found by ?maintainer) or ask a question on a relevant R task view, such as https://cran.r-project.org/web/views/Econometrics.html . (or any other that you judge to be more appropriate). Cheers, Bert On Tue, Apr 23, 2024 at 9:41?AM Richard Hardy <brukalinis at gmail.com> wrote:> > A copy of this question can be found on Cross Validated: > https://stats.stackexchange.com/questions/645362 > > I am estimating a system of seemingly unrelated regressions (SUR) in R. > Each of the equations has one unique regressor and one common regressor. I > am using `gmm::sysGmm` and am experimenting with different weighting > matrices. I get the same results (point estimates, standard errors and > anything else that I can see (**except** for the value of the $J$-test) > regardless of the weighting matrix. I do not think this is correct. > The phenomenon persists regardless of what type of covariance matrix > estimator I use: `MDS`, `CondHom` or `HAC`. > It also persists regardless of whether I use unrestricted estimation or > restrict the coefficients on one of the variables (the common regressor) to > be equal across equations. > > **Question:** Why does system GMM via `gmm::sysGmm` yield identical results > for any weighting matrix? How can I make it yield proper results that vary > with the weighting matrix (if that makes sense and I am not mistaken, of > course)? > > ------------------------------ R code for a reproducible example > > library(gmm) > library(systemfit) > > # Generate and prepare the data > n <- 1000 # sample size > m <- 100 # length of the "second part" of the sample > N <- 3 # number of equations > set.seed(321); x <- matrix(rnorm(n*N),ncol=N); colnames(x) <- > paste0("x",1:N) # generate regressors > dummy <- c( rep(0,n-m), rep(1,m) ) # generate a common regressor > x <- cbind(x,dummy) # include the common regressor with the > rest of the regressors > set.seed(123); y <- matrix(rnorm(n*N),ncol=N); colnames(y) <- > paste0("y",1:N) # a placeholder for dependent variables > for(i in 1:N){ > y[,i] <- i + sqrt(i)*x[,i] - i*dummy + y[,i]*15*sqrt(i) > # y[,i] is a linear function of x[,i] and dummy, > # plus an error term with equation-specific variance > } > data1 <- as.data.frame(cbind(y,x)) # create a data frame of all data (y and > x) > > # Create the model equations and moment conditions > ES_g = ES_h <- list() # ES ~ equation system > for(i in 1:N){ > ES_g[[i]] <- as.formula(assign(paste0("eq",i), value=paste0("y",i," ~ > x",i," + dummy"))) # define linear equations of SUR > ES_h[[i]] <- as.formula(assign(paste0("eq",i), value=paste0( "~ > x",i," + dummy"))) # define the moment conditions for GMM > } > > # Estimate a WLS-type weighting matrix to use as a user-specified weighting > matrix in GMM > m0 <- systemfit(formula=ES_g, method="OLS", data=data1) > OLSmat <- diag(diag(m0$residCov)); Wmat <- solve(OLSmat) > > # Choose the type of covariance matrix in GMM > vc1 <- "MDS" > vc1 <- "CondHom" > vc1 <- "HAC" > #vc1 <- "TrueFixed" > > # Choose between restricted and unrestricted estimation > cec1=NULL # unrestricted > cec1=3 # restrict the coefficient on the dummy to be equal across > equations > > # Estimate the model with `sysGmm` using different weighting matrices: > identity, "optimal" and manually specified > m1a <- sysGmm(g=ES_g, h=ES_h, wmatrix="ident" , weightsMatrix=NULL, > vcov=vc1, crossEquConst=cec1, data=data1); summary(m1a) > m1b <- sysGmm(g=ES_g, h=ES_h, wmatrix="optimal", weightsMatrix=NULL, > vcov=vc1, crossEquConst=cec1, data=data1); summary(m1b) > m1c <- sysGmm(g=ES_g, h=ES_h, weightsMatrix=Wmat, > vcov=vc1, crossEquConst=cec1, data=data1); summary(m1c) > > ------------------------------ R session info: > > R version 4.3.3 (2024-02-29 ucrt) > Platform: x86_64-w64-mingw32/x64 (64-bit) > Running under: Windows 10 x64 (build 19045) > > Matrix products: default > > locale: > [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United > States.utf8 > [3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C > > [5] LC_TIME=English_United States.utf8 > > time zone: Europe/Berlin > tzcode source: internal > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] systemfit_1.1-30 lmtest_0.9-40 zoo_1.8-12 car_3.1-2 > carData_3.0-5 Matrix_1.6-1 > [7] gmm_1.8 sandwich_3.0-2 > > loaded via a namespace (and not attached): > [1] MASS_7.3-60.0.1 compiler_4.3.3 tools_4.3.3 abind_1.4-5 > rstudioapi_0.15.0 grid_4.3.3 > [7] lattice_0.22-5 > > ------------------------------ > > Kind regards, > Richard > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.