├── DESCRIPTION ├── MD5 ├── NAMESPACE ├── NEWS.md ├── R ├── deprecated.R ├── detect_lin_dep_alias.R ├── est_cce.R ├── est_ggls.R ├── est_gmm.R ├── est_ldv.R ├── est_mg.R ├── est_pi.R ├── est_plm.R ├── est_plm.list.R ├── est_vcm.R ├── experimental.R ├── groupGenerics_pseries.R ├── is.pconsecutive.R ├── make.pconsecutive_pbalanced.R ├── plm-package.R ├── test_cd.R ├── test_cips.R ├── test_general.R ├── test_granger.R ├── test_serial.R ├── test_uroot.R ├── tool_argvalues.R ├── tool_ercomp.R ├── tool_methods.R ├── tool_misc.R ├── tool_model.extract.R ├── tool_pdata.frame.R ├── tool_ranfixef.R ├── tool_transformations.R ├── tool_transformations_collapse.R └── tool_vcovG.R ├── README.md ├── THANKS ├── build ├── partial.rdb └── vignette.rds ├── data ├── Cigar.rda ├── Crime.rda ├── EmplUK.rda ├── Gasoline.rda ├── Grunfeld.rda ├── Hedonic.rda ├── LaborSupply.rda ├── Males.rda ├── Parity.rda ├── Produc.rda ├── RiceFarms.rda ├── Snmesp.rda ├── SumHes.rda └── Wages.rda ├── inst ├── CITATION ├── DPD98.R ├── DPD98.txt ├── REFERENCES.bib ├── WORDLIST └── doc │ ├── A_plmPackage.R │ ├── A_plmPackage.Rmd │ ├── A_plmPackage.html │ ├── B_plmFunction.R │ ├── B_plmFunction.Rmd │ ├── B_plmFunction.html │ ├── C_plmModelComponents.R │ ├── C_plmModelComponents.Rmd │ └── C_plmModelComponents.html ├── man ├── Cigar.Rd ├── Crime.Rd ├── EmplUK.Rd ├── Gasoline.Rd ├── Grunfeld.Rd ├── Hedonic.Rd ├── LaborSupply.Rd ├── Males.Rd ├── Parity.Rd ├── Produc.Rd ├── RiceFarms.Rd ├── Snmesp.Rd ├── SumHes.Rd ├── Wages.Rd ├── aneweytest.Rd ├── cipstest.Rd ├── cortab.Rd ├── detect.lindep.Rd ├── ercomp.Rd ├── fixef.plm.Rd ├── has.intercept.Rd ├── index.plm.Rd ├── is.pbalanced.Rd ├── is.pconsecutive.Rd ├── is.pseries.Rd ├── lag.plm.Rd ├── make.dummies.Rd ├── make.pbalanced.Rd ├── make.pconsecutive.Rd ├── model.frame.pdata.frame.Rd ├── mtest.Rd ├── nobs.plm.Rd ├── pFtest.Rd ├── pbgtest.Rd ├── pbltest.Rd ├── pbnftest.Rd ├── pbsytest.Rd ├── pcce.Rd ├── pcdtest.Rd ├── pdata.frame.Rd ├── pdim.Rd ├── pdwtest.Rd ├── pggls.Rd ├── pgmm.Rd ├── pgrangertest.Rd ├── phansitest.Rd ├── pht.Rd ├── phtest.Rd ├── piest.Rd ├── pldv.Rd ├── plm-deprecated.Rd ├── plm-package.Rd ├── plm.Rd ├── plm.fast.Rd ├── plmtest.Rd ├── pmg.Rd ├── pmodel.response.Rd ├── pooltest.Rd ├── predict.plm.Rd ├── pseries.Rd ├── pseriesfy.Rd ├── punbalancedness.Rd ├── purtest.Rd ├── pvar.Rd ├── pvcm.Rd ├── pwaldtest.Rd ├── pwartest.Rd ├── pwfdtest.Rd ├── pwtest.Rd ├── r.squared.Rd ├── ranef.plm.Rd ├── re-export_functions.Rd ├── sargan.Rd ├── summary.plm.Rd ├── vcovBK.Rd ├── vcovDC.Rd ├── vcovG.Rd ├── vcovHC.plm.Rd ├── vcovNW.Rd ├── vcovSCC.Rd └── within_intercept.Rd ├── tests └── test_Evaluation.R └── vignettes ├── A_plmPackage.Rmd ├── B_plmFunction.Rmd └── C_plmModelComponents.Rmd /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: plm 2 | Version: 2.6-6 3 | Date: 2025-04-04 4 | Title: Linear Models for Panel Data 5 | Authors@R: c(person(given = "Yves", family = "Croissant", role = c("aut"), email = "yves.croissant@univ-reunion.fr"), 6 | person(given = "Giovanni", family = "Millo", role = c("aut"), email = "giovanni.millo@deams.units.it"), 7 | person(given = "Kevin", family = "Tappe", role = c("aut", "cre"), email = "kevin.tappe@bwi.uni-stuttgart.de"), 8 | person(given = "Ott", family = "Toomet", role = "ctb", email = "otoomet@gmail.com"), 9 | person(given = "Christian", family = "Kleiber", role = "ctb", email = "Christian.Kleiber@unibas.ch"), 10 | person(given = "Achim", family = "Zeileis", role = "ctb", email = "Achim.Zeileis@R-project.org"), 11 | person(given = "Arne", family = "Henningsen", role = "ctb", email = "arne.henningsen@googlemail.com"), 12 | person(given = "Liviu", family = "Andronic", role = "ctb"), 13 | person(given = "Nina", family = "Schoenfelder", role = "ctb")) 14 | Depends: R (>= 3.2.0) 15 | Imports: MASS, bdsmatrix, collapse (>= 1.8.9), zoo, nlme, sandwich, 16 | lattice, lmtest, maxLik, Rdpack, Formula, stats 17 | Suggests: AER, car, statmod, urca, pder, texreg, knitr, rmarkdown, 18 | fixest, lfe 19 | Description: A set of estimators for models and (robust) covariance matrices, and tests for panel data 20 | econometrics, including within/fixed effects, random effects, between, first-difference, 21 | nested random effects as well as instrumental-variable (IV) and Hausman-Taylor-style models, 22 | panel generalized method of moments (GMM) and general FGLS models, 23 | mean groups (MG), demeaned MG, and common correlated effects (CCEMG) and pooled (CCEP) estimators 24 | with common factors, variable coefficients and limited dependent variables models. 25 | Test functions include model specification, serial correlation, cross-sectional dependence, 26 | panel unit root and panel Granger (non-)causality. Typical references are general econometrics 27 | text books such as Baltagi (2021), Econometric Analysis of Panel Data (), 28 | Hsiao (2014), Analysis of Panel Data (), and Croissant and Millo (2018), 29 | Panel Data Econometrics with R (). 30 | License: GPL (>= 2) 31 | VignetteBuilder: knitr 32 | URL: https://cran.r-project.org/package=plm, 33 | https://github.com/ycroissant/plm 34 | BugReports: https://github.com/ycroissant/plm/issues 35 | RoxygenNote: 7.3.2 36 | RdMacros: Rdpack 37 | Encoding: UTF-8 38 | NeedsCompilation: no 39 | Packaged: 2025-04-03 22:01:12 UTC; kevin 40 | Author: Yves Croissant [aut], 41 | Giovanni Millo [aut], 42 | Kevin Tappe [aut, cre], 43 | Ott Toomet [ctb], 44 | Christian Kleiber [ctb], 45 | Achim Zeileis [ctb], 46 | Arne Henningsen [ctb], 47 | Liviu Andronic [ctb], 48 | Nina Schoenfelder [ctb] 49 | Maintainer: Kevin Tappe 50 | Repository: CRAN 51 | Date/Publication: 2025-04-04 15:00:02 UTC 52 | -------------------------------------------------------------------------------- /R/experimental.R: -------------------------------------------------------------------------------- 1 | residuals_overall_exp.plm <- function(x, ...) { #### experimental, non-exported function 2 | # residuals_overall.plm: gives the residuals of the "overall"/outer model for all types of plm models. 3 | # In the future, this could be integrated with residuals.plm by some argument, e.g., overall = FALSE (default). 4 | # see also test file tests/test_residuals_overall_fitted_exp.R 5 | 6 | # no na.action eval yet 7 | 8 | model <- describe(x, "model") 9 | 10 | if (model == "ht") stop("model \"ht\" not (yet?) supported") 11 | 12 | # for all effects of within models: residuals of (quasi-)demeaned (inner) model 13 | # are also the residuals of the "overall" model 14 | if (model == "random") { 15 | # get untransformed data to calculate overall residuals 16 | X <- model.matrix(x, model = "pooling") 17 | y <- pmodel.response(x, model = "pooling") 18 | # take care of any aliased coefficients: 19 | # they are not in x$coefficients but assoc. variables are still present in model.matrix 20 | if (any(x$aliased, na.rm = TRUE)) { # na.rm = TRUE because currently, RE tw unbalanced models set aliased differently 21 | X <- X[ , !x$aliased, drop = FALSE] 22 | } 23 | 24 | est <- as.numeric(tcrossprod(coef(x), X)) 25 | res <- y - est 26 | names(res) <- rownames(X) 27 | 28 | # make residuals a pseries 29 | res <- structure(res, index = index(x), class = c("pseries", class(res))) 30 | 31 | } else { # all plm models except random (and also except ht) 32 | res <- residuals(x) 33 | } 34 | return(res) 35 | } 36 | 37 | residuals_overall_e_exp <- function(object) { ### experimental non-exported function 38 | ## residuals of "overall" RE model minus random effects (=e_it) 39 | ## e.g.: two-way model: residual_overall_it = random_component_individual_i + random_component_time_t + e_it 40 | model <- describe(object, "model") 41 | if (model != "random") stop("only for random effect models") 42 | obj.eff <- describe(object, "effect") 43 | res_ov <- residuals_overall_exp.plm(object) 44 | if (obj.eff == "twoways") { 45 | res_ov_e <- res_ov - ranef(object, "individual")[index(object, "id")] - ranef(object, "time")[index(object, "time")] 46 | } else { 47 | res_ov_e <- res_ov - ranef(object)[index(object, if(obj.eff == "individual") "id" else "time")] 48 | } 49 | names(res_ov_e) <- names(res_ov) 50 | return(res_ov_e) 51 | } 52 | 53 | fitted_exp.plm <- function(x, ...) { #### experimental, non-exported function 54 | # fitted_exp.plm: gives the fitted values of all types of plm models by subtracting the overall 55 | # residuals from the untransformed response variable; does not have 56 | # a model argument so it is not as versatile as 'fitted.plm' below. 57 | # see also test file tests/test_residuals_overall_fitted_exp.R 58 | model <- describe(x, "model") 59 | res <- residuals_overall_exp.plm(x) 60 | 61 | # For "between" and "fd" models, the number of fitted values is not equal to the 62 | # number of original observations. Thus, model.frame cannot be used but rather 63 | # pmodel.response because it has the right length. However, pmodel.response 64 | # shall not be used for the other models because we want the untransformed data. 65 | y <- if (model %in% c("between", "fd")) pmodel.response(x) else model.frame(x)[ , 1L] 66 | return(y - res) 67 | } 68 | 69 | 70 | 71 | # check_propagation_correct_class: helper function 72 | # Function checks if the class and storage mode (type) of an object match 73 | # and corrects its class attribute if not 74 | # 75 | # A mismatch can occur if a pseries of lower class and type logical or integer 76 | # are propagated to higher type by an arithmetic operation as R's arithmetic 77 | # operations do not change the first value of class attribute for 78 | # c("pseries", "logical/integer"). However, using groupGenerics as wrapper around 79 | # pseries objects, this does not happen anymore. 80 | # E.g., 81 | # x <- c(1L, 2L, 3L) 82 | # x + 1.5 83 | # results in class propagation from class "integer" to "numeric" 84 | # but not if x is of class c("myclass", "integer") 85 | check_propagation_correct_class <- function(x) { 86 | # x: a pseries object (usually) 87 | if (any((pos <- inherits(x, c("logical" ,"integer", "numeric"), which = TRUE)) > 0)) { 88 | pos <- pos[pos > 0] # non-matches in inherits(..., which = TRUE) results in 0 89 | switch(typeof(x), 90 | "double" = { attr(x, "class")[pos] <- "numeric" }, 91 | "integer" = { attr(x, "class")[pos] <- "integer" }, 92 | "complex" = { attr(x, "class")[pos] <- "complex" } 93 | ) 94 | } 95 | return(x) 96 | } 97 | 98 | -------------------------------------------------------------------------------- /R/groupGenerics_pseries.R: -------------------------------------------------------------------------------- 1 | ## groupGenerics for operations on pseries 2 | ## see ?groupGeneric 3 | ## see tests/test_groupGenerics_pseries.R for examples 4 | ## 5 | ## implemented wrappers for groups Ops, Math, Complex 6 | ## 7 | ## group generic for Summary (all, any, sum, prod, min, max, range) not needed 8 | ## as functions in this group do not change the data type 9 | ## 10 | ## groupGenerics need to be registered in NAMESPACE 11 | ## 12 | ## groupGenerics are used to allow automatic propagation to higher/lower data type 13 | ## when operations are performed on pseries, 14 | ## e.g., class c("pseries", "integer") -> c("pseries", "numeric") when a function 15 | ## takes an integer as input and outputs a numeric. Without the group generics, 16 | ## the class of the results would stay as c("pseries", "integer") while the values 17 | ## themselves are numerics. The associated test file demonstrates the behaviour, 18 | ## see tests/test_groupGenerics_pseries.R 19 | 20 | 21 | ## helper functions: remove_pseries_features and add_pseries_features 22 | remove_pseries_features <- function(x) { 23 | 24 | # debug: 25 | # if (!is.pseries(x)) warning("removing pseries features now but object was not a proper pseries before") 26 | 27 | attr(x, "index") <- NULL 28 | # unclass is simpler and faster than previously (up to and incl. rev. 1307) used 29 | # combination of check_propagation_correct_class() and class() <- setdiff(class(<.>), "pseries") 30 | # unclass handles propagation and keeps names but coerces factor to integer 31 | x <- if(!is.factor(x)) unclass(x) else { class(x) <- setdiff(class(x), "pseries"); x } 32 | x 33 | } 34 | 35 | add_pseries_features <- function(x, index) { 36 | # debug: 37 | # if (is.null(index)) warning("'index' is null") 38 | 39 | attr(x, "index") <- index 40 | class(x) <- unique(c("pseries", class(x))) 41 | return(x) 42 | } 43 | 44 | #' @export 45 | Ops.pseries <- function(e1, e2) { 46 | # print("Ops.pseries executed!") # debug output 47 | 48 | miss_e2 <- missing(e2) 49 | e1_pseries <- e2_pseries <- FALSE 50 | # either one or both could be pseries 51 | if(inherits(e1, "pseries")) { 52 | e1_pseries <- TRUE 53 | index_e1 <- attr(e1, "index") 54 | e1 <- remove_pseries_features(e1) 55 | } 56 | 57 | if(!miss_e2 && inherits(e2, "pseries")) { 58 | e2_pseries <- TRUE 59 | index_e2 <- attr(e2, "index") 60 | e2 <- remove_pseries_features(e2) 61 | } 62 | 63 | res <- if(!miss_e2) get(.Generic)(e1, e2) else get(.Generic)(e1) 64 | 65 | # result could be, e.g., matrix. So check if adding back pseries features 66 | # makes sense (e.g., do not create something of class c("pseries", "matrix")). 67 | # Need is.atomic because is.vector is too strict, however need to sort out 68 | # some other data types 69 | add_back_pseries <- if(is.atomic(res) && !is.matrix(res) && !is.pairlist(res)) TRUE else FALSE 70 | if(add_back_pseries) { 71 | if(miss_e2 && e1_pseries) relevant_index <- index_e1 72 | if( e1_pseries && !e2_pseries) relevant_index <- index_e1 73 | if(!e1_pseries && e2_pseries) relevant_index <- index_e2 74 | if( e1_pseries && e2_pseries) { 75 | # decide on index for result: 76 | # if objects vary in length: shorter object is recycled by R 77 | # -> must take index of non-recycled object (= longer pseries) 78 | # 79 | # Also, base R uses the names of the first operand -> additional justification 80 | # to assign index_e1 in case of same number of rows 81 | relevant_index <- if(nrow(index_e1) >= nrow(index_e2)) index_e1 else index_e2 82 | 83 | # do not warn anymore (since rev. 1181) 84 | # if ((nrow(index_e1) == nrow(index_e2)) && !isTRUE(all.equal(index_e1, index_e2))) 85 | # warning("indexes of pseries have same length but not same content: result was assigned first operand's index") 86 | } 87 | res <- add_pseries_features(res, relevant_index) 88 | } 89 | 90 | return(res) 91 | } 92 | 93 | #' @export 94 | Math.pseries <- function(x, ...) { 95 | # print("Math.pseries executed!") # debug output 96 | 97 | index <- attr(x, "index") 98 | x <- remove_pseries_features(x) 99 | 100 | x <- get(.Generic)(x, ...) 101 | x <- add_pseries_features(x, index) 102 | return(x) 103 | } 104 | 105 | #' @export 106 | Complex.pseries <- function(z) { 107 | # print("Complex.pseries executed!") # debug output 108 | 109 | index <- attr(z, "index") 110 | z <- remove_pseries_features(z) 111 | 112 | z <- get(.Generic)(z) 113 | z <- add_pseries_features(z, index) 114 | return(z) 115 | } 116 | 117 | -------------------------------------------------------------------------------- /R/tool_argvalues.R: -------------------------------------------------------------------------------- 1 | ## This file contain named vectors of the acceptable values for different 2 | ## arguments used in plm functions. 3 | 4 | 5 | random.method.list <- c(swar = "Swamy-Arora", 6 | walhus = "Wallace-Hussain", 7 | amemiya = "Amemiya", 8 | nerlove = "Nerlove", 9 | ht = "Hausman-Taylor") 10 | 11 | effect.plm.list <- c(individual = "Oneway (individual) effect", 12 | time = "Oneway (time) effect", 13 | twoways = "Twoways effects", 14 | nested = "Nested effects") 15 | 16 | effect.pvcm.list <- c(individual = "Oneway (individual) effect", 17 | time = "Oneway (time) effect") 18 | 19 | effect.pggls.list <- c(individual = "Oneway (individual) effect", 20 | time = "Oneway (time) effect") 21 | 22 | effect.pgmm.list <- c(individual = "Oneway (individual) effect", 23 | twoways = "Twoways effects") 24 | 25 | model.plm.list <- c(pooling = "Pooling", 26 | within = "Within", 27 | between = "Between", 28 | random = "Random Effect", 29 | ht = "Hausman-Taylor", 30 | fd = "First-Difference") 31 | 32 | ht.method.list <- c(ht = "Hausman-Taylor estimator", 33 | am = "Amemiya-MaCurdy estimator", 34 | bms = "Breusch-Mizon-Schmidt estimator") 35 | 36 | model.pvcm.list <- c(within = "No-pooling model", 37 | random = "Random coefficients model") 38 | 39 | model.pggls.list <- c(within = "Within FGLS model", 40 | random = "General FGLS model", 41 | pooling = "General FGLS model", 42 | fd = "First-Difference FGLS model") 43 | 44 | model.pgmm.list <- c(onestep = "One-step model", 45 | twosteps = "Two-steps model") 46 | 47 | model.pgmm.transformation.list <- c(d = "Difference GMM", 48 | ld = "System GMM") 49 | 50 | model.pcce.list <- c(ccemg = "Mean Groups model", 51 | ccep = "Pooled model") 52 | 53 | model.pmg.list <- c(mg = "Mean Groups model", 54 | dmg = "Demeaned Mean Groups model", 55 | cmg = "Common Correlated Effects Mean Groups model") 56 | 57 | inst.method.list <- c(bvk = "Balestra-Varadharajan-Krishnakumar", 58 | baltagi = "Baltagi", 59 | am = "Amemiya-MaCurdy", 60 | bms = "Breusch-Mizon-Schmidt") 61 | 62 | # robust.list and weights.list are not used anywhere... 63 | robust.list <- c(white1 = "White 1", 64 | white2 = "White 2", 65 | arellano = "Arellano") 66 | 67 | weights.list <- c(HC0 = "HC0", 68 | HC1 = "HC1", 69 | HC2 = "HC2", 70 | HC3 = "HC3", 71 | HC4 = "HC4") 72 | 73 | oneof <- function(x){ 74 | x <- names(x) 75 | last <- x[length(x)] 76 | x <- x[-length(x)] 77 | x <- paste(x,collapse=", ") 78 | x <- paste(x,last,sep=" and ") 79 | x 80 | } 81 | 82 | plm.arg <- c("formula", "data", "subset", "weights", "na.action", "effect", "model", 83 | "instruments", "random.method", "inst.method", "index") 84 | 85 | pgmm.fsm.list <- c(I = "I", 86 | G = "G", 87 | GI = "GI", 88 | full = "full") 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The `plm` Package - Linear Models and Tests for Panel Data 2 | 3 | 4 | [![CRAN status](https://www.r-pkg.org/badges/version/plm)](https://CRAN.R-project.org/package=plm) 5 | [![Downloads](https://cranlogs.r-pkg.org/badges/plm)](https://CRAN.R-project.org/package=plm) 6 | 7 | 8 | ## About 9 | 10 | `plm` is a package for panel data econometrics for the **R** statistical computing 11 | environment. The package includes functions for model estimation, testing, robust 12 | covariance matrix estimation, panel data manipulation and information. It was 13 | first published on **CRAN** in 2006. 14 | 15 | Be sure to read the NEWS on [CRAN](https://cran.r-project.org/package=plm) (or 16 | in the [development repository](https://github.com/ycroissant/plm/blob/main/NEWS.md)) 17 | for any changes in new releases (new features, bugfixes, other improvements, ...). 18 | 19 | Non-exhaustive function overview: 20 | 21 | - Functions to estimate models: 22 | - `plm`: panel data estimators (within/fixed effects, random effects, between, 23 | first-difference, nested random effects), incl. instrumental-variable 24 | estimation techniques (IV) and Hausman-Taylor-style models, 25 | - `pgmm`: generalized method of moments (GMM) estimation for panel data, 26 | - `pggls`: estimation of general feasible generalized least squares models, 27 | - `pmg`: mean groups (MG), demeaned MG and common correlated effects (CCEMG) estimators, 28 | - `pcce`: estimators for common correlated effects mean groups (CCEMG) and pooled (CCEP) for panel data with common factors, 29 | - `pvcm`: variable coefficients models, 30 | - `pldv`: panel estimators for limited dependent variables. 31 | 32 | - Testing functions: 33 | - model specification (`phtest`, `pFtest`, `pooltest`, `plmtest`, `pwaldtest`, `piest`, `aneweytest`, `mtest`, `sargan`), 34 | - serial correlation (`pbgtest`, `pwfdtest`, `pbnftest`, `pdwtest`, `pwartest`, `pbsytest`, `pbltest`), 35 | - cross-sectional dependence (`pcdtest`), 36 | - panel unit root (`purtest`, `cipstest`, `phansitest`), 37 | - panel Granger (non-)causality (`pgrangertest`). 38 | 39 | - Robust covariance matrix estimators (incl. various weighting schemes 40 | for small sample adjustment): 41 | - `vcovHC`: Arellano (1987), White (1980), 42 | - `vcovBK`: Beck and Katz (1995) (PCSE), 43 | - `vcovNW`: Newey and West (1987), 44 | - `vcovDC`: double-clustering robust (Thompson (2011), Cameron et al. (2011)), 45 | - `vcovSCC`: Driscoll and Kraay (1998). 46 | 47 | - An enhanced data frame, called `pdata.frame`, to deal with data sets for which 48 | observations are identified by a combination of two indexes. 49 | 50 | - Panel data transformation functions (e.g., `Within`, `Between`, `between`, `lag`, 51 | `lead`, `diff`). 52 | 53 | - Other functions relating to panel data sets, e.g.: 54 | - checks for panel data dimensions (individual, time, group) and balancedness (`pdim`), 55 | - checks for panel balancedness (`is.pbalanced`) and consecutiveness (regularity) (`is.pconsecutive`) 56 | as well as functions to change data to conform to these properties 57 | (`make.pbalanced`, `make.pconsecutive`), 58 | - measures for unbalancedness of data (`punbalancedness`) (Ahrens/Pincus (1981)). 59 | 60 | 61 | ## Installation 62 | 63 | To install the released version from **CRAN**: 64 | 65 | ```{r} 66 | install.packages("plm") 67 | ``` 68 | 69 | The package's CRAN website is . 70 | 71 | The development of package `plm` takes place on GitHub at . 72 | To install the development version from **GitHub**, use, e.g.: 73 | ```{r} 74 | # install.packages("remotes") # remove '#' if pkg 'remotes' is not installed 75 | remotes::install_github("ycroissant/plm") 76 | ``` 77 | 78 | 79 | ## Documentation 80 | 81 | Package plm comes with documentation: Besides the usual help pages for each function, 82 | the vignettes provide a gentle introduction to the package and some functions. 83 | Vignettes are available at the package's CRAN website 84 | and can be browsed from within R by `browseVignettes("plm")`. 85 | 86 | New package users are advised to start with the first vignette 87 | *Panel data econometrics in R: the plm package* for an overview of the package. 88 | A more in-depth treatment of estimation of error component models and instrument 89 | variable models is in the second vignette *Estimation of error component models 90 | with the plm function*. 91 | 92 | Further, many textbooks treat package `plm` and/or use it in their examples: 93 | 94 | * Croissant/Millo, *Panel Data Econometrics with R*, 2019, John Wiley & Sons, Hoboken. 95 | 96 | * Kleiber/Zeileis, *Applied Econometrics with R*, 2008, Springer, New York. Esp. 97 | chapter 3.6. 98 | 99 | * Hanck/Arnold/Gerber/Schmelzer, *Econometrics with R*, online book 100 | . Esp. chapter 10. 101 | 102 | * Heiss, *Using R for Introductory Econometrics*, 2nd edition, 2020, 103 | Independent Publishing, Düsseldorf, also available online at . 104 | A companion book using R to Wooldridge, *Introductory Econometrics*, esp. 105 | chapters 13-14. 106 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | We've benefited from comments and bug reports from many people on 2 | previous versions of the package. We would like to thank especially : 3 | Arne Henningsen, Christian Kleiber, Katarzyna Kopczewska, Ott Toomet, 4 | and Achim Zeileis. 5 | 6 | The package was greatly improved during the revision of the Journal of 7 | Statistical Software 27(2) article, thanks to the helpful comments of three 8 | anonymous referees. We especially thank the co-editor of this journal, 9 | Achim Zeileis, for many interesting comments and suggestions. 10 | -------------------------------------------------------------------------------- /build/partial.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/build/partial.rdb -------------------------------------------------------------------------------- /build/vignette.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/build/vignette.rds -------------------------------------------------------------------------------- /data/Cigar.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Cigar.rda -------------------------------------------------------------------------------- /data/Crime.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Crime.rda -------------------------------------------------------------------------------- /data/EmplUK.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/EmplUK.rda -------------------------------------------------------------------------------- /data/Gasoline.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Gasoline.rda -------------------------------------------------------------------------------- /data/Grunfeld.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Grunfeld.rda -------------------------------------------------------------------------------- /data/Hedonic.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Hedonic.rda -------------------------------------------------------------------------------- /data/LaborSupply.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/LaborSupply.rda -------------------------------------------------------------------------------- /data/Males.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Males.rda -------------------------------------------------------------------------------- /data/Parity.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Parity.rda -------------------------------------------------------------------------------- /data/Produc.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Produc.rda -------------------------------------------------------------------------------- /data/RiceFarms.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/RiceFarms.rda -------------------------------------------------------------------------------- /data/Snmesp.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Snmesp.rda -------------------------------------------------------------------------------- /data/SumHes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/SumHes.rda -------------------------------------------------------------------------------- /data/Wages.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/plm/59318399c6eb7bcaeb1d0560f1ce08882f0f55c1/data/Wages.rda -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry(bibtype = "Book", 2 | title = "Panel Data Econometrics with {R}", 3 | author = c(person(given = "Yves", 4 | family = "Croissant", 5 | email = "yves.croissant@univ-reunion.fr"), 6 | person(given = "Giovanni", 7 | family = "Millo", 8 | email = "giovanni.millo@deams.units.it")), 9 | publisher = "Wiley", 10 | year = "2018", 11 | header = "To cite plm in publications use:" 12 | ) 13 | 14 | bibentry(bibtype = "Article", 15 | title = "Panel Data Econometrics in {R}: The {plm} Package", 16 | author = c(person(given = "Yves", 17 | family = "Croissant", 18 | email = "yves.croissant@univ-reunion.fr"), 19 | person(given = "Giovanni", 20 | family = "Millo", 21 | email = "giovanni.millo@deams.units.it")), 22 | journal = "Journal of Statistical Software", 23 | year = "2008", 24 | volume = "27", 25 | number = "2", 26 | pages = "1--43", 27 | doi = "10.18637/jss.v027.i02", 28 | header = "To cite plm in publications use:" 29 | ) 30 | 31 | bibentry(bibtype = "Article", 32 | title = "Robust Standard Error Estimators for Panel Models: A Unifying Approach", 33 | author = person(given = "Giovanni", 34 | family = "Millo", 35 | email = "giovanni.millo@deams.units.it"), 36 | journal = "Journal of Statistical Software", 37 | year = "2017", 38 | volume = "82", 39 | number = "3", 40 | pages = "1--27", 41 | doi = "10.18637/jss.v082.i03", 42 | header = "For the covariance matrix estimators in plm, please cite:" 43 | ) 44 | -------------------------------------------------------------------------------- /inst/DPD98.R: -------------------------------------------------------------------------------- 1 | # @---------------------------- one-step estimates -----------------------------@ 2 | 3 | vc=s*inxmx; @ covariance matrix @ 4 | stderr=sqrt(diag(vc)); @ standard errors @ 5 | trat=b./stderr; @ t-ratios @ 6 | pvt=2*cdfnc(abs(trat)); @ p-values @ 7 | 8 | if m0125; 9 | 10 | if sc2; @ serial correlation tests @ 11 | v2v=y2y+b'x2x*b-y2x*b-b'x2y; 12 | v2x=y2x-b'x2x; 13 | vhat2=(yky2+b'xkx2*b-2*ykx2*b-2*v2x*inxmx*xz*inzkz*(zky2-zkx2*b)+ 14 | v2x*inxmx*v2x')*s; 15 | m2=v2v./sqrt(vhat2); 16 | pvm2=2*cdfnc(abs(m2)); 17 | endif; 18 | 19 | if sc1; 20 | v1v=y1y+b'x1x*b-y1x*b-b'x1y; 21 | v1x=y1x-b'x1x; 22 | vhat1=(yky1+b'xkx1*b-2*ykx1*b-2*v1x*inxmx*xz*inzkz*(zky1-zkx1*b)+ 23 | v1x*inxmx*v1x')*s; 24 | m1=v1v./sqrt(vhat1); 25 | pvm1=2*cdfnc(abs(m1)); 26 | endif; 27 | 28 | # @------------------ robust statistics for one-step estimates -----------------@ 29 | 30 | xax2=xzinzkz*zkz2*xzinzkz'; 31 | 32 | vc2=inxmx*xax2*inxmx; @ covariance matrix @ 33 | stderr2=sqrt(diag(vc2)); @ standard errors @ 34 | trat2=b./stderr2; @ t-values @ 35 | pvt2=2*cdfnc(abs(trat2)); @ p-values @ 36 | 37 | if sc2; @ serial correlation tests @ 38 | if m34; 39 | v2v=y2y+b'x2x*b-y2x*b-b'x2y; 40 | v2x=y2x-b'x2x; 41 | endif; 42 | vhat2w=vomv2w-(2.*v2x*inxmx*xzinzkz*zomv2w)+(v2x*vc2*v2x'); 43 | m2w=v2v./sqrt(vhat2w); 44 | pvm2w=2*cdfnc(abs(m2w)); 45 | endif; 46 | 47 | if sc1; 48 | if m34; 49 | v1v=y1y+b'x1x*b-y1x*b-b'x1y; 50 | v1x=y1x-b'x1x; 51 | endif; 52 | vhat1w=vomv1w-(2.*v1x*inxmx*xzinzkz*zomv1w)+(v1x*vc2*v1x'); 53 | m1w=v1v./sqrt(vhat1w); 54 | pvm1w=2*cdfnc(abs(m1w)); 55 | endif; 56 | 57 | # @---------------------------- Two-step estimates -----------------------------@ 58 | 59 | if (iiv==1 and ijus==0); 60 | 61 | if imike==0; 62 | inzkz2=invpd(zkz2); 63 | else; 64 | inzkz2=pinv(zkz2); 65 | endif; 66 | clear zkz2; 67 | 68 | bxmx=xz*inzkz2*zx; bxmy=xz*inzkz2*zy; 69 | 70 | bvc=invpd(bxmx); @ covariance matrix @ 71 | 72 | bb=bvc*bxmy; @ coefficient vector @ 73 | bstderr=sqrt(diag(bvc)); @ standard errors @ 74 | btrat=bb./bstderr; @ t-values @ 75 | bpvt=2*cdfnc(abs(btrat)); @ p-values @ 76 | 77 | if sc2; @ serial correlation tests @ 78 | bv2v=y2y+bb'x2x*bb-y2x*bb-bb'x2y; 79 | bvhat2w=vomv2w-(2.*v2x*bvc*xz*inzkz2*zomv2w)+(v2x*bvc*v2x'); 80 | bm2w=bv2v./sqrt(bvhat2w); 81 | pvbm2w=2*cdfnc(abs(bm2w)); 82 | endif; 83 | 84 | if sc1; 85 | bv1v=y1y+bb'x1x*bb-y1x*bb-bb'x1y; 86 | bvhat1w=vomv1w-(2.*v1x*bvc*xz*inzkz2*zomv1w)+(v1x*bvc*v1x'); 87 | bm1w=bv1v./sqrt(bvhat1w); 88 | pvbm1w=2*cdfnc(abs(bm1w)); 89 | endif; 90 | -------------------------------------------------------------------------------- /inst/DPD98.txt: -------------------------------------------------------------------------------- 1 | # @---------------------------- one-step estimates -----------------------------@ 2 | 3 | vc=s*inxmx; @ covariance matrix @ 4 | stderr=sqrt(diag(vc)); @ standard errors @ 5 | trat=b./stderr; @ t-ratios @ 6 | pvt=2*cdfnc(abs(trat)); @ p-values @ 7 | 8 | if m0125; 9 | 10 | if sc2; @ serial correlation tests @ 11 | v2v=y2y+b'x2x*b-y2x*b-b'x2y; 12 | v2x=y2x-b'x2x; 13 | vhat2=(yky2+b'xkx2*b-2*ykx2*b-2*v2x*inxmx*xz*inzkz*(zky2-zkx2*b)+ 14 | v2x*inxmx*v2x')*s; 15 | m2=v2v./sqrt(vhat2); 16 | pvm2=2*cdfnc(abs(m2)); 17 | endif; 18 | 19 | if sc1; 20 | v1v=y1y+b'x1x*b-y1x*b-b'x1y; 21 | v1x=y1x-b'x1x; 22 | vhat1=(yky1+b'xkx1*b-2*ykx1*b-2*v1x*inxmx*xz*inzkz*(zky1-zkx1*b)+ 23 | v1x*inxmx*v1x')*s; 24 | m1=v1v./sqrt(vhat1); 25 | pvm1=2*cdfnc(abs(m1)); 26 | endif; 27 | 28 | # @------------------ robust statistics for one-step estimates -----------------@ 29 | 30 | xax2=xzinzkz*zkz2*xzinzkz'; 31 | 32 | vc2=inxmx*xax2*inxmx; @ covariance matrix @ 33 | stderr2=sqrt(diag(vc2)); @ standard errors @ 34 | trat2=b./stderr2; @ t-values @ 35 | pvt2=2*cdfnc(abs(trat2)); @ p-values @ 36 | 37 | if sc2; @ serial correlation tests @ 38 | if m34; 39 | v2v=y2y+b'x2x*b-y2x*b-b'x2y; 40 | v2x=y2x-b'x2x; 41 | endif; 42 | vhat2w=vomv2w-(2.*v2x*inxmx*xzinzkz*zomv2w)+(v2x*vc2*v2x'); 43 | m2w=v2v./sqrt(vhat2w); 44 | pvm2w=2*cdfnc(abs(m2w)); 45 | endif; 46 | 47 | if sc1; 48 | if m34; 49 | v1v=y1y+b'x1x*b-y1x*b-b'x1y; 50 | v1x=y1x-b'x1x; 51 | endif; 52 | vhat1w=vomv1w-(2.*v1x*inxmx*xzinzkz*zomv1w)+(v1x*vc2*v1x'); 53 | m1w=v1v./sqrt(vhat1w); 54 | pvm1w=2*cdfnc(abs(m1w)); 55 | endif; 56 | 57 | # @---------------------------- Two-step estimates -----------------------------@ 58 | 59 | if (iiv==1 and ijus==0); 60 | 61 | if imike==0; 62 | inzkz2=invpd(zkz2); 63 | else; 64 | inzkz2=pinv(zkz2); 65 | endif; 66 | clear zkz2; 67 | 68 | bxmx=xz*inzkz2*zx; bxmy=xz*inzkz2*zy; 69 | 70 | bvc=invpd(bxmx); @ covariance matrix @ 71 | 72 | bb=bvc*bxmy; @ coefficient vector @ 73 | bstderr=sqrt(diag(bvc)); @ standard errors @ 74 | btrat=bb./bstderr; @ t-values @ 75 | bpvt=2*cdfnc(abs(btrat)); @ p-values @ 76 | 77 | if sc2; @ serial correlation tests @ 78 | bv2v=y2y+bb'x2x*bb-y2x*bb-bb'x2y; 79 | bvhat2w=vomv2w-(2.*v2x*bvc*xz*inzkz2*zomv2w)+(v2x*bvc*v2x'); 80 | bm2w=bv2v./sqrt(bvhat2w); 81 | pvbm2w=2*cdfnc(abs(bm2w)); 82 | endif; 83 | 84 | if sc1; 85 | bv1v=y1y+bb'x1x*bb-y1x*bb-bb'x1y; 86 | bvhat1w=vomv1w-(2.*v1x*bvc*xz*inzkz2*zomv1w)+(v1x*bvc*v1x'); 87 | bm1w=bv1v./sqrt(bvhat1w); 88 | pvbm1w=2*cdfnc(abs(bm1w)); 89 | endif; 90 | -------------------------------------------------------------------------------- /inst/doc/C_plmModelComponents.R: -------------------------------------------------------------------------------- 1 | ## ----setup, echo=FALSE-------------------------------------------------------- 2 | library("knitr") 3 | opts_chunk$set(message = FALSE, warning = FALSE) 4 | 5 | ## ----------------------------------------------------------------------------- 6 | library("plm") 7 | data("SeatBelt", package = "pder") 8 | SeatBelt$occfat <- with(SeatBelt, log(farsocc / (vmtrural + vmturban))) 9 | pSB <- pdata.frame(SeatBelt) 10 | 11 | ## ----------------------------------------------------------------------------- 12 | formols <- occfat ~ log(usage) + log(percapin) 13 | mfols <- model.frame(pSB, formols) 14 | Xols <- model.matrix(mfols) 15 | y <- pmodel.response(mfols) 16 | coef(lm.fit(Xols, y)) 17 | 18 | ## ----------------------------------------------------------------------------- 19 | coef(plm(formols, SeatBelt, model = "pooling")) 20 | 21 | ## ----------------------------------------------------------------------------- 22 | formiv1 <- occfat ~ log(usage) + log(percapin) | log(percapin) + ds + dp + dsp 23 | formiv2 <- occfat ~ log(usage) + log(percapin) | . - log(usage) + ds + dp + dsp 24 | 25 | ## ----------------------------------------------------------------------------- 26 | mfSB1 <- model.frame(pSB, formiv1) 27 | X1 <- model.matrix(mfSB1, rhs = 1) 28 | W1 <- model.matrix(mfSB1, rhs = 2) 29 | head(X1, 3) ; head(W1, 3) 30 | 31 | ## ----------------------------------------------------------------------------- 32 | library("Formula") 33 | head(model.frame(Formula(formiv2), SeatBelt), 3) 34 | head(model.frame(Formula(formiv2), SeatBelt, dot = "previous"), 3) 35 | 36 | ## ----------------------------------------------------------------------------- 37 | mfSB2 <- model.frame(pSB, formiv2) 38 | X2 <- model.matrix(mfSB2, rhs = 1) 39 | W2 <- model.matrix(mfSB2, rhs = 2) 40 | head(X2, 3) ; head(W2, 3) 41 | 42 | ## ----------------------------------------------------------------------------- 43 | HX1 <- lm.fit(W1, X1)$fitted.values 44 | head(HX1, 3) 45 | 46 | ## ----------------------------------------------------------------------------- 47 | coef(lm.fit(HX1, y)) 48 | 49 | ## ----------------------------------------------------------------------------- 50 | coef(plm(formiv1, SeatBelt, model = "pooling")) 51 | 52 | ## ----------------------------------------------------------------------------- 53 | coef(AER::ivreg(formiv1, data = SeatBelt)) 54 | 55 | ## ----eval = FALSE, include = FALSE-------------------------------------------- 56 | # X2 <- model.matrix(Formula(form1), mfSB, rhs = 2, dot = "previous") 57 | # 58 | # formols <- occfat ~ log(usage) + log(percapin) | . - log(usage) + ds + dp + dsp 59 | # 60 | # form1 <- occfat ~ log(usage) + log(percapin) + log(unemp) + log(meanage) + 61 | # log(precentb) + log(precenth) + log(densrur) + log(densurb) + 62 | # log(viopcap) + log(proppcap) + log(vmtrural) + log(vmturban) + 63 | # log(fueltax) + lim65 + lim70p + mlda21 + bac08 64 | # form2 <- . ~ . | . - log(usage) + ds + dp +dsp 65 | # 66 | # jorm1 <- occfat ~ log(usage) + log(percapin) + log(unemp) + log(meanage) + 67 | # log(precentb) + log(precenth) + log(densrur) + log(densurb) + 68 | # log(viopcap) + log(proppcap) + log(vmtrural) + log(vmturban) + 69 | # log(fueltax) + lim65 + lim70p + mlda21 + bac08 | . - log(usage) + 70 | # ds + dp + dsp 71 | # jorm2 <- noccfat ~ . | . 72 | 73 | -------------------------------------------------------------------------------- /man/Cigar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Cigar} 5 | \alias{Cigar} 6 | \title{Cigarette Consumption} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{state}{state abbreviation} 11 | \item{year}{the year} 12 | \item{price}{price per pack of cigarettes} 13 | \item{pop}{population} 14 | \item{pop16}{population above the age of 16} 15 | \item{cpi}{consumer price index (1983=100)} 16 | \item{ndi}{per capita disposable income} 17 | \item{sales}{cigarette sales in packs per capita} 18 | \item{pimin}{minimum price in adjoining states per pack of cigarettes} 19 | } 20 | } 21 | \source{ 22 | Online complements to Baltagi (2001): 23 | 24 | \url{https://www.wiley.com/legacy/wileychi/baltagi/} 25 | 26 | Online complements to Baltagi (2013): 27 | 28 | \url{https://bcs.wiley.com/he-bcs/Books?action=resource&bcsId=4338&itemId=1118672321&resourceId=13452} 29 | } 30 | \description{ 31 | a panel of 46 observations from 1963 to 1992 32 | } 33 | \details{ 34 | \emph{total number of observations} : 1380 35 | 36 | \emph{observation} : regional 37 | 38 | \emph{country} : United States 39 | } 40 | \references{ 41 | \insertRef{BALT:01}{plm} 42 | 43 | \insertRef{BALT:13}{plm} 44 | 45 | \insertRef{BALT:LEVI:92}{plm} 46 | 47 | \insertRef{BALT:GRIF:XION:00}{plm} 48 | } 49 | \keyword{datasets} 50 | -------------------------------------------------------------------------------- /man/Crime.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Crime} 5 | \alias{Crime} 6 | \title{Crime in North Carolina} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{county}{county identifier} 11 | \item{year}{year from 1981 to 1987} 12 | \item{crmrte}{crimes committed per person} 13 | \item{prbarr}{'probability' of arrest} 14 | \item{prbconv}{'probability' of conviction} 15 | \item{prbpris}{'probability' of prison sentence} 16 | \item{avgsen}{average sentence, days} 17 | \item{polpc}{police per capita} 18 | \item{density}{people per square mile} 19 | \item{taxpc}{tax revenue per capita} 20 | \item{region}{factor. One of 'other', 'west' or 'central'.} 21 | \item{smsa}{factor. (Also called "urban".) Does the individual reside in a SMSA (standard metropolitan statistical area)?} 22 | \item{pctmin}{percentage minority in 1980} 23 | \item{wcon}{weekly wage in construction} 24 | \item{wtuc}{weekly wage in transportation, utilities, communications} 25 | \item{wtrd}{weekly wage in wholesale and retail trade} 26 | \item{wfir}{weekly wage in finance, insurance and real estate} 27 | \item{wser}{weekly wage in service industry} 28 | \item{wmfg}{weekly wage in manufacturing} 29 | \item{wfed}{weekly wage in federal government} 30 | \item{wsta}{weekly wage in state government} 31 | \item{wloc}{weekly wage in local government} 32 | \item{mix}{offence mix: face-to-face/other} 33 | \item{pctymle}{percentage of young males (between ages 15 to 24)} 34 | \item{lcrmrte}{log of crimes committed per person} 35 | \item{lprbarr}{log of 'probability' of arrest} 36 | \item{lprbconv}{log of 'probability' of conviction} 37 | \item{lprbpris}{log of 'probability' of prison sentence} 38 | \item{lavgsen}{log of average sentence, days} 39 | \item{lpolpc}{log of police per capita} 40 | \item{ldensity}{log of people per square mile} 41 | \item{ltaxpc}{log of tax revenue per capita} 42 | \item{lpctmin}{log of percentage minority in 1980} 43 | \item{lwcon}{log of weekly wage in construction} 44 | \item{lwtuc}{log of weekly wage in transportation, utilities, communications} 45 | \item{lwtrd}{log of weekly wage in wholesale and retail trade} 46 | \item{lwfir}{log of weekly wage in finance, insurance and real estate} 47 | \item{lwser}{log of weekly wage in service industry} 48 | \item{lwmfg}{log of weekly wage in manufacturing} 49 | \item{lwfed}{log of weekly wage in federal government} 50 | \item{lwsta}{log of weekly wage in state government} 51 | \item{lwloc}{log of weekly wage in local government} 52 | \item{lmix}{log of offence mix: face-to-face/other} 53 | \item{lpctymle}{log of percentage of young males (between ages 15 to 24)}} 54 | } 55 | \source{ 56 | Journal of Applied Econometrics Data Archive (complements Baltagi 57 | (2006)): 58 | 59 | \url{http://qed.econ.queensu.ca/jae/2006-v21.4/baltagi/} 60 | 61 | Online complements to Baltagi (2001): 62 | 63 | \url{https://www.wiley.com/legacy/wileychi/baltagi/} 64 | 65 | Online complements to Baltagi (2013): 66 | 67 | \url{https://bcs.wiley.com/he-bcs/Books?action=resource&bcsId=4338&itemId=1118672321&resourceId=13452} 68 | 69 | See also Journal of Applied Econometrics data archive entry for 70 | Baltagi (2006) at 71 | \url{http://qed.econ.queensu.ca/jae/2006-v21.4/baltagi/}. 72 | } 73 | \description{ 74 | a panel of 90 observational units (counties) from 1981 to 1987 75 | } 76 | \details{ 77 | \emph{total number of observations} : 630 78 | 79 | \emph{observation} : regional 80 | 81 | \emph{country} : United States 82 | 83 | The variables l* (lcrmrte, lprbarr, ...) contain the pre-computed logarithms 84 | of the base variables as found in the original data set. Note that these 85 | values slightly differ from what R's log() function yields for the base 86 | variables. In order to reproduce examples from the literature, the 87 | pre-computed logs need to be used, otherwise the results differ slightly. 88 | } 89 | \references{ 90 | \insertRef{CORN:TRUM:94}{plm} 91 | 92 | \insertRef{BALT:06}{plm} 93 | 94 | \insertRef{BALT:01}{plm} 95 | 96 | \insertRef{BALT:13}{plm} 97 | } 98 | \keyword{datasets} 99 | -------------------------------------------------------------------------------- /man/EmplUK.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{EmplUK} 5 | \alias{EmplUK} 6 | \title{Employment and Wages in the United Kingdom} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{firm}{firm index} 11 | \item{year}{year} 12 | \item{sector}{the sector of activity} 13 | \item{emp}{employment} 14 | \item{wage}{wages} 15 | \item{capital}{capital} 16 | \item{output}{output} 17 | } 18 | } 19 | \source{ 20 | \insertRef{AREL:BOND:91}{plm} 21 | } 22 | \description{ 23 | An unbalanced panel of 140 observations from 1976 to 1984 24 | } 25 | \details{ 26 | \emph{total number of observations} : 1031 27 | 28 | \emph{observation} : firms 29 | 30 | \emph{country} : United Kingdom 31 | } 32 | \keyword{datasets} 33 | -------------------------------------------------------------------------------- /man/Gasoline.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Gasoline} 5 | \alias{Gasoline} 6 | \title{Gasoline Consumption} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{country}{a factor with 18 levels} 11 | \item{year}{the year} 12 | \item{lgaspcar}{logarithm of motor gasoline consumption per car} 13 | \item{lincomep}{logarithm of real per-capita income} 14 | \item{lrpmg}{logarithm of real motor gasoline price} 15 | \item{lcarpcap}{logarithm of the stock of cars per capita} 16 | } 17 | } 18 | \source{ 19 | Online complements to Baltagi (2001): 20 | 21 | \url{https://www.wiley.com/legacy/wileychi/baltagi/} 22 | 23 | Online complements to Baltagi (2013): 24 | 25 | \url{https://bcs.wiley.com/he-bcs/Books?action=resource&bcsId=4338&itemId=1118672321&resourceId=13452} 26 | } 27 | \description{ 28 | A panel of 18 observations from 1960 to 1978 29 | } 30 | \details{ 31 | \emph{total number of observations} : 342 32 | 33 | \emph{observation} : country 34 | 35 | \emph{country} : OECD 36 | } 37 | \references{ 38 | \insertRef{BALT:01}{plm} 39 | 40 | \insertRef{BALT:13}{plm} 41 | 42 | \insertRef{BALT:GRIF:83}{plm} 43 | } 44 | \keyword{datasets} 45 | -------------------------------------------------------------------------------- /man/Grunfeld.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Grunfeld} 5 | \alias{Grunfeld} 6 | \title{Grunfeld's Investment Data} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{firm}{observation} 11 | \item{year}{date} 12 | \item{inv}{gross Investment} 13 | \item{value}{value of the firm} 14 | \item{capital}{stock of plant and equipment} } 15 | } 16 | \source{ 17 | Online complements to Baltagi (2001): 18 | 19 | \url{https://www.wiley.com/legacy/wileychi/baltagi/} 20 | 21 | \url{https://www.wiley.com/legacy/wileychi/baltagi/supp/Grunfeld.fil} 22 | 23 | Online complements to Baltagi (2013): 24 | 25 | \url{https://bcs.wiley.com/he-bcs/Books?action=resource&bcsId=4338&itemId=1118672321&resourceId=13452} 26 | } 27 | \description{ 28 | A balanced panel of 10 observational units (firms) from 1935 to 1954 29 | } 30 | \details{ 31 | \emph{total number of observations} : 200 32 | 33 | \emph{observation} : production units 34 | 35 | \emph{country} : United States 36 | } 37 | \note{ 38 | The Grunfeld data as provided in package \code{plm} is the 39 | same data as used in Baltagi (2001), see \strong{Examples} below. 40 | 41 | NB:\cr Various versions of the Grunfeld data circulate 42 | online. Also, various text books (and also varying among editions) 43 | and papers use different subsets of the original Grunfeld data, 44 | some of which contain errors in a few data points compared to the 45 | original data used by Grunfeld (1958) in his PhD thesis. See 46 | Kleiber/Zeileis (2010) and its accompanying website for a 47 | comparison of various Grunfeld data sets in use. 48 | } 49 | \examples{ 50 | 51 | \dontrun{ 52 | # Compare plm's Grunfeld data to Baltagi's (2001) Grunfeld data: 53 | data("Grunfeld", package="plm") 54 | Grunfeld_baltagi2001 <- read.csv("http://www.wiley.com/legacy/wileychi/ 55 | baltagi/supp/Grunfeld.fil", sep="", header = FALSE) 56 | library(compare) 57 | compare::compare(Grunfeld, Grunfeld_baltagi2001, allowAll = T) # same data set 58 | } 59 | 60 | } 61 | \references{ 62 | \insertRef{BALT:01}{plm} 63 | 64 | \insertRef{BALT:13}{plm} 65 | 66 | \insertRef{GRUN:58}{plm} 67 | 68 | \insertRef{KLEI:ZEIL:10}{plm} 69 | 70 | website accompanying the paper with various variants of the 71 | Grunfeld data: 72 | \url{https://www.zeileis.org/grunfeld/}. 73 | } 74 | \seealso{ 75 | For the complete Grunfeld data (11 firms), see 76 | \link[AER:Grunfeld]{AER::Grunfeld}, in the \code{AER} package. 77 | } 78 | \keyword{datasets} 79 | -------------------------------------------------------------------------------- /man/Hedonic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Hedonic} 5 | \alias{Hedonic} 6 | \title{Hedonic Prices of Census Tracts in the Boston Area} 7 | \format{ 8 | A dataframe containing: 9 | \describe{ 10 | \item{mv}{median value of owner--occupied homes} 11 | \item{crim}{crime rate} 12 | \item{zn}{proportion of 25,000 square feet residential lots} 13 | \item{indus}{proportion of no--retail business acres} 14 | \item{chas}{is the tract bounds the Charles River?} 15 | \item{nox}{annual average nitrogen oxide concentration in parts per hundred million} 16 | \item{rm}{average number of rooms} 17 | \item{age}{proportion of owner units built prior to 1940} 18 | \item{dis}{weighted distances to five employment centers in the Boston area} 19 | \item{rad}{index of accessibility to radial highways} 20 | \item{tax}{full value property tax rate ($/$10,000)} 21 | \item{ptratio}{pupil/teacher ratio} 22 | \item{blacks}{proportion of blacks in the population} 23 | \item{lstat}{proportion of population that is lower status} 24 | \item{townid}{town identifier} } 25 | } 26 | \source{ 27 | Online complements to Baltagi (2001): 28 | 29 | \url{https://www.wiley.com/legacy/wileychi/baltagi/} 30 | 31 | Online complements to Baltagi (2013): 32 | 33 | \url{https://bcs.wiley.com/he-bcs/Books?action=resource&bcsId=4338&itemId=1118672321&resourceId=13452} 34 | } 35 | \description{ 36 | A cross-section 37 | } 38 | \details{ 39 | \emph{number of observations} : 506 40 | 41 | \emph{observation} : regional 42 | 43 | \emph{country} : United States 44 | } 45 | \references{ 46 | \insertRef{BALT:01}{plm} 47 | 48 | \insertRef{BALT:13}{plm} 49 | 50 | \insertRef{BESL:KUH:WELS:80}{plm} 51 | 52 | \insertRef{HARR:RUBI:78}{plm} 53 | } 54 | \keyword{datasets} 55 | -------------------------------------------------------------------------------- /man/LaborSupply.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{LaborSupply} 5 | \alias{LaborSupply} 6 | \title{Wages and Hours Worked} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{lnhr}{log of annual hours worked} 11 | \item{lnwg}{log of hourly wage} 12 | \item{kids}{number of children} 13 | \item{age}{age} 14 | \item{disab}{bad health} 15 | \item{id}{id} 16 | \item{year}{year} 17 | } 18 | } 19 | \source{ 20 | Online complements to Ziliak (1997). 21 | 22 | Journal of Business Economics and Statistics web site: 23 | \url{https://amstat.tandfonline.com/loi/ubes20/}. 24 | } 25 | \description{ 26 | A panel of 532 observations from 1979 to 1988 27 | } 28 | \details{ 29 | \emph{number of observations} : 5320 30 | } 31 | \references{ 32 | \insertRef{CAME:TRIV:05}{plm} 33 | 34 | \insertRef{ZILI:97}{plm} 35 | } 36 | \keyword{datasets} 37 | -------------------------------------------------------------------------------- /man/Males.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Males} 5 | \alias{Males} 6 | \title{Wages and Education of Young Males} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{nr}{identifier} 11 | \item{year}{year} 12 | \item{school}{years of schooling} 13 | \item{exper}{years of experience (computed as \code{age-6-school})} 14 | \item{union}{wage set by collective bargaining?} 15 | \item{ethn}{a factor with levels \verb{black, hisp, other}} 16 | \item{married}{married?} 17 | \item{health}{health problem?} 18 | \item{wage}{log of hourly wage} 19 | \item{industry}{a factor with 12 levels} 20 | \item{occupation}{a factor with 9 levels} 21 | \item{residence}{a factor with levels \verb{rural_area, north_east, northern_central, south}} 22 | } 23 | } 24 | \source{ 25 | Journal of Applied Econometrics data archive 26 | \url{http://qed.econ.queensu.ca/jae/1998-v13.2/vella-verbeek/}. 27 | } 28 | \description{ 29 | A panel of 545 observations from 1980 to 1987 30 | } 31 | \details{ 32 | \emph{total number of observations} : 4360 33 | 34 | \emph{observation} : individuals 35 | 36 | \emph{country} : United States 37 | } 38 | \references{ 39 | \insertRef{VELL:VERB:98}{plm} 40 | 41 | \insertRef{VERB:04}{plm} 42 | } 43 | \keyword{datasets} 44 | -------------------------------------------------------------------------------- /man/Parity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Parity} 5 | \alias{Parity} 6 | \title{Purchasing Power Parity and other parity relationships} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{country}{country codes: a factor with 17 levels} 11 | \item{time}{the quarter index, 1973Q1-1998Q4} 12 | \item{ls}{log spot exchange rate vs. USD} 13 | \item{lp}{log price level} 14 | \item{is}{short term interest rate} 15 | \item{il}{long term interest rate} 16 | \item{ld}{log price differential vs. USA} 17 | \item{uis}{U.S. short term interest rate} 18 | \item{uil}{U.S. long term interest rate} } 19 | } 20 | \source{ 21 | \insertRef{COAK:FUER:SMIT:06}{plm} 22 | } 23 | \description{ 24 | A panel of 104 quarterly observations from 1973Q1 to 1998Q4 25 | } 26 | \details{ 27 | \emph{total number of observations} : 1768 28 | 29 | \emph{observation} : country 30 | 31 | \emph{country} : OECD 32 | } 33 | \references{ 34 | \insertRef{COAK:FUER:SMIT:06}{plm} 35 | 36 | \insertRef{DRIS:KRAA:98}{plm} 37 | } 38 | \keyword{datasets} 39 | -------------------------------------------------------------------------------- /man/Produc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Produc} 5 | \alias{Produc} 6 | \title{US States Production} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{state}{the state} 11 | \item{year}{the year} 12 | \item{region}{the region} 13 | \item{pcap}{public capital stock} 14 | \item{hwy}{highway and streets} 15 | \item{water}{water and sewer facilities} 16 | \item{util}{other public buildings and structures} 17 | \item{pc}{private capital stock} 18 | \item{gsp}{gross state product} 19 | \item{emp}{labor input measured by the employment in non--agricultural payrolls} 20 | \item{unemp}{state unemployment rate} } 21 | } 22 | \source{ 23 | Online complements to Baltagi (2001): 24 | 25 | \url{https://www.wiley.com/legacy/wileychi/baltagi/} 26 | 27 | Online complements to Baltagi (2013): 28 | 29 | \url{https://bcs.wiley.com/he-bcs/Books?action=resource&bcsId=4338&itemId=1118672321&resourceId=13452} 30 | } 31 | \description{ 32 | A panel of 48 observations from 1970 to 1986 33 | } 34 | \details{ 35 | \emph{total number of observations} : 816 36 | 37 | \emph{observation} : regional 38 | 39 | \emph{country} : United States 40 | } 41 | \references{ 42 | \insertRef{BALT:01}{plm} 43 | 44 | \insertRef{BALT:13}{plm} 45 | 46 | \insertRef{BALT:PINN:95}{plm} 47 | 48 | \insertRef{MUNN:90}{plm} 49 | } 50 | \keyword{datasets} 51 | -------------------------------------------------------------------------------- /man/RiceFarms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{RiceFarms} 5 | \alias{RiceFarms} 6 | \title{Production of Rice in Indonesia} 7 | \format{ 8 | A dataframe containing : 9 | \describe{ 10 | \item{id}{the farm identifier} 11 | 12 | \item{size}{the total area cultivated with rice, measured in hectares} 13 | 14 | \item{status}{land status, on of \code{'owner'} (non sharecroppers, 15 | owner operators or leaseholders or both), \code{'share'} 16 | (sharecroppers), \code{'mixed'} (mixed of the two previous status)} 17 | 18 | \item{varieties}{one of \code{'trad'} (traditional varieties), 19 | \code{'high'} (high yielding varieties) and \code{'mixed'} (mixed 20 | varieties)} 21 | 22 | \item{bimas}{bIMAS is an intensification program; one of 23 | \code{'no'} (non-bimas farmer), \code{'yes'} (bimas farmer) or 24 | \code{'mixed'} (part but not all of farmer's land was registered to 25 | be in the bimas program)} 26 | 27 | \item{seed}{seed in kilogram} 28 | 29 | \item{urea}{urea in kilogram} 30 | 31 | \item{phosphate}{phosphate in kilogram} 32 | 33 | \item{pesticide}{pesticide cost in Rupiah} 34 | 35 | \item{pseed}{price of seed in Rupiah per kg} 36 | 37 | \item{purea}{price of urea in Rupiah per kg} 38 | 39 | \item{pphosph}{price of phosphate in Rupiah per kg} 40 | 41 | \item{hiredlabor}{hired labor in hours} 42 | 43 | \item{famlabor}{family labor in hours} 44 | 45 | \item{totlabor}{total labor (excluding harvest labor)} 46 | 47 | \item{wage}{labor wage in Rupiah per hour} 48 | 49 | \item{goutput}{gross output of rice in kg} 50 | 51 | \item{noutput}{net output, gross output minus harvesting cost (paid 52 | in terms of rice)} 53 | 54 | \item{price}{price of rough rice in Rupiah per kg} 55 | 56 | \item{region}{one of \code{'wargabinangun'}, \code{'langan'}, 57 | \code{'gunungwangi'}, \code{'malausma'}, \code{'sukaambit'}, 58 | \code{'ciwangi'}} 59 | 60 | } 61 | } 62 | \source{ 63 | \insertRef{FENG:HORR:12}{plm} 64 | } 65 | \description{ 66 | a panel of 171 observations 67 | } 68 | \details{ 69 | \emph{number of observations} : 1026 70 | 71 | \emph{observation} : farms 72 | 73 | \emph{country} : Indonesia 74 | } 75 | \keyword{datasets} 76 | -------------------------------------------------------------------------------- /man/Snmesp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Snmesp} 5 | \alias{Snmesp} 6 | \title{Employment and Wages in Spain} 7 | \format{ 8 | A data frame containing: 9 | 10 | \describe{ 11 | \item{firm}{firm index} 12 | \item{year}{year} 13 | \item{n}{log of employment} 14 | \item{w}{log of wages} 15 | \item{y}{log of real output} 16 | \item{i}{log of intermediate inputs} 17 | \item{k}{log of real capital stock} 18 | \item{f}{real cash flow} } 19 | } 20 | \source{ 21 | Journal of Business Economics and Statistics data archive: 22 | 23 | \url{https://amstat.tandfonline.com/loi/ubes20/}. 24 | } 25 | \description{ 26 | A panel of 738 observations from 1983 to 1990 27 | } 28 | \details{ 29 | \emph{total number of observations}: 5904 30 | 31 | \emph{observation}: firms 32 | 33 | \emph{country}: Spain 34 | } 35 | \references{ 36 | \insertRef{ALON:AREL:99}{plm} 37 | } 38 | \keyword{datasets} 39 | -------------------------------------------------------------------------------- /man/SumHes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{SumHes} 5 | \alias{SumHes} 6 | \title{The Penn World Table, v. 5} 7 | \format{ 8 | A data frame containing : 9 | \describe{ 10 | \item{year}{the year} 11 | \item{country}{the country name (factor)} 12 | \item{opec}{OPEC member?} 13 | \item{com}{communist regime? } 14 | \item{pop}{country's population (in thousands)} 15 | \item{gdp}{real GDP per capita (in 1985 US dollars)} 16 | \item{sr}{saving rate (in percent)}} 17 | } 18 | \source{ 19 | Online supplements to Hayashi (2000). 20 | 21 | \url{http://fhayashi.fc2web.com/datasets.htm} 22 | } 23 | \description{ 24 | A panel of 125 observations from 1960 to 1985 25 | } 26 | \details{ 27 | \emph{total number of observations} : 3250 28 | 29 | \emph{observation} : country 30 | 31 | \emph{country} : World 32 | } 33 | \references{ 34 | \insertRef{HAYA:00}{plm} 35 | 36 | \insertRef{SUMM:HEST:91}{plm} 37 | } 38 | \keyword{datasets} 39 | -------------------------------------------------------------------------------- /man/Wages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{data} 4 | \name{Wages} 5 | \alias{Wages} 6 | \title{Panel Data of Individual Wages} 7 | \format{ 8 | A data frame containing: 9 | \describe{ 10 | \item{exp}{years of full-time work experience.} 11 | \item{wks}{weeks worked.} 12 | \item{bluecol}{blue collar?} 13 | \item{ind}{works in a manufacturing industry?} 14 | \item{south}{resides in the south?} 15 | \item{smsa}{resides in a standard metropolitan statistical area?} 16 | \item{married}{married?} 17 | \item{sex}{a factor with levels \code{"male"} and \code{"female"}} 18 | \item{union}{individual's wage set by a union contract?} 19 | \item{ed}{years of education.} 20 | \item{black}{is the individual black?} 21 | \item{lwage}{logarithm of wage.} } 22 | } 23 | \source{ 24 | Online complements to Baltagi (2001): 25 | 26 | \url{https://www.wiley.com/legacy/wileychi/baltagi/} 27 | 28 | Online complements to Baltagi (2013): 29 | 30 | \url{https://bcs.wiley.com/he-bcs/Books?action=resource&bcsId=4338&itemId=1118672321&resourceId=13452} 31 | } 32 | \description{ 33 | A panel of 595 individuals from 1976 to 1982, taken from the Panel Study of 34 | Income Dynamics (PSID).\cr\cr The data are organized as a stacked time 35 | series/balanced panel, see \strong{Examples} on how to convert to a 36 | \code{pdata.frame}. 37 | } 38 | \details{ 39 | \emph{total number of observations} : 4165 40 | 41 | \emph{observation} : individuals 42 | 43 | \emph{country} : United States 44 | } 45 | \examples{ 46 | 47 | # data set 'Wages' is organized as a stacked time series/balanced panel 48 | data("Wages", package = "plm") 49 | Wag <- pdata.frame(Wages, index=595) 50 | 51 | } 52 | \references{ 53 | \insertRef{BALT:01}{plm} 54 | 55 | \insertRef{BALT:13}{plm} 56 | 57 | \insertRef{CORN:RUPE:88}{plm} 58 | } 59 | \keyword{datasets} 60 | -------------------------------------------------------------------------------- /man/aneweytest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_pi.R 3 | \name{aneweytest} 4 | \alias{aneweytest} 5 | \title{Angrist and Newey's version of Chamberlain test for fixed effects} 6 | \usage{ 7 | aneweytest(formula, data, subset, na.action, index = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{formula}{a symbolic description for the model to be estimated,} 11 | 12 | \item{data}{a \code{data.frame},} 13 | 14 | \item{subset}{see \code{\link[=lm]{lm()}},} 15 | 16 | \item{na.action}{see \code{\link[=lm]{lm()}},} 17 | 18 | \item{index}{the indexes,} 19 | 20 | \item{\dots}{further arguments.} 21 | } 22 | \value{ 23 | An object of class \code{"htest"}. 24 | } 25 | \description{ 26 | Angrist and Newey's version of the Chamberlain test 27 | } 28 | \details{ 29 | Angrist and Newey's test is based on the results of the artifactual 30 | regression of the within residuals on the covariates for all the 31 | periods. 32 | } 33 | \examples{ 34 | 35 | data("RiceFarms", package = "plm") 36 | aneweytest(log(goutput) ~ log(seed) + log(totlabor) + log(size), RiceFarms, index = "id") 37 | 38 | } 39 | \references{ 40 | \insertRef{ANGR:NEWE:91}{plm} 41 | } 42 | \seealso{ 43 | \code{\link[=piest]{piest()}} for Chamberlain's test 44 | } 45 | \author{ 46 | Yves Croissant 47 | } 48 | \keyword{htest} 49 | -------------------------------------------------------------------------------- /man/cipstest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_cips.R 3 | \name{cipstest} 4 | \alias{cipstest} 5 | \title{Cross-sectionally Augmented IPS Test for Unit Roots in Panel Models} 6 | \usage{ 7 | cipstest( 8 | x, 9 | lags = 2L, 10 | type = c("trend", "drift", "none"), 11 | model = c("cmg", "mg", "dmg"), 12 | truncated = FALSE, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{an object of class \code{"pseries"},} 18 | 19 | \item{lags}{integer, lag order for Dickey-Fuller augmentation,} 20 | 21 | \item{type}{one of \code{"trend"} (default), \code{"drift"}, \code{"none"},} 22 | 23 | \item{model}{one of \code{"cmg"} (default), \code{"mg"}, \code{"dmg"},} 24 | 25 | \item{truncated}{logical, specifying whether to calculate the 26 | truncated version of the test (default: \code{FALSE}),} 27 | 28 | \item{\dots}{further arguments passed to \code{critvals.cips} 29 | (non-exported function).} 30 | } 31 | \value{ 32 | An object of class \code{"htest"}. 33 | } 34 | \description{ 35 | Cross-sectionally augmented Im, Pesaran and Shin (IPS) test for 36 | unit roots in panel models. 37 | } 38 | \details{ 39 | Pesaran's \insertCite{pes07}{plm} cross-sectionally augmented version of 40 | the IPS unit root test \insertCite{IM:PESAR:SHIN:03}{plm} (H0: \code{pseries} 41 | has a unit root) is a so-called second-generation panel unit root test: it 42 | is in fact robust against cross-sectional dependence, provided that the default 43 | \code{model="cmg"} is calculated. Else one can obtain the standard 44 | (\code{model="mg"}) or cross-sectionally demeaned (\code{model="dmg"}) 45 | versions of the IPS test. 46 | 47 | Argument \code{type} controls how the test is executed: 48 | \itemize{ 49 | \item \code{"none"}: no intercept, no trend (Case I in \insertCite{pes07}{plm}), 50 | \item \code{"drift"}: with intercept, no trend (Case II), 51 | \item \code{"trend"} (default): with intercept, with trend (Case III). 52 | } 53 | } 54 | \examples{ 55 | 56 | data("Produc", package = "plm") 57 | Produc <- pdata.frame(Produc, index=c("state", "year")) 58 | ## check whether the gross state product (gsp) is trend-stationary 59 | cipstest(Produc$gsp, type = "trend") 60 | 61 | } 62 | \references{ 63 | \insertAllCited{} 64 | } 65 | \seealso{ 66 | \code{\link[=purtest]{purtest()}}, \code{\link[=phansitest]{phansitest()}} 67 | } 68 | \author{ 69 | Giovanni Millo 70 | } 71 | \keyword{htest} 72 | -------------------------------------------------------------------------------- /man/cortab.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_cd.R 3 | \name{cortab} 4 | \alias{cortab} 5 | \title{Cross--sectional correlation matrix} 6 | \usage{ 7 | cortab(x, grouping, groupnames = NULL, value = "statistic", ...) 8 | } 9 | \arguments{ 10 | \item{x}{an object of class \code{pseries}} 11 | 12 | \item{grouping}{grouping variable,} 13 | 14 | \item{groupnames}{a character vector of group names,} 15 | 16 | \item{value}{to complete,} 17 | 18 | \item{\dots}{further arguments.} 19 | } 20 | \value{ 21 | A matrix with average correlation coefficients within a group 22 | (diagonal) and between groups (off-diagonal). 23 | } 24 | \description{ 25 | Computes the cross--sectional correlation matrix 26 | } 27 | \examples{ 28 | 29 | data("Grunfeld", package = "plm") 30 | pGrunfeld <- pdata.frame(Grunfeld) 31 | grp <- c(rep(1, 100), rep(2, 50), rep(3, 50)) # make 3 groups 32 | cortab(pGrunfeld$value, grouping = grp, groupnames = c("A", "B", "C")) 33 | 34 | } 35 | \keyword{htest} 36 | -------------------------------------------------------------------------------- /man/ercomp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_ercomp.R 3 | \name{ercomp} 4 | \alias{ercomp} 5 | \alias{ercomp.plm} 6 | \alias{ercomp.pdata.frame} 7 | \alias{ercomp.formula} 8 | \alias{print.ercomp} 9 | \title{Estimation of the error components} 10 | \usage{ 11 | ercomp(object, ...) 12 | 13 | \method{ercomp}{plm}(object, ...) 14 | 15 | \method{ercomp}{pdata.frame}( 16 | object, 17 | effect = c("individual", "time", "twoways", "nested"), 18 | method = NULL, 19 | models = NULL, 20 | dfcor = NULL, 21 | index = NULL, 22 | ... 23 | ) 24 | 25 | \method{ercomp}{formula}( 26 | object, 27 | data, 28 | effect = c("individual", "time", "twoways", "nested"), 29 | method = NULL, 30 | models = NULL, 31 | dfcor = NULL, 32 | index = NULL, 33 | ... 34 | ) 35 | 36 | \method{print}{ercomp}(x, digits = max(3, getOption("digits") - 3), ...) 37 | } 38 | \arguments{ 39 | \item{object}{a \code{formula} or a \code{plm} object,} 40 | 41 | \item{\dots}{further arguments.} 42 | 43 | \item{effect}{the effects introduced in the model, see \code{\link[=plm]{plm()}} for 44 | details,} 45 | 46 | \item{method}{method of estimation for the variance components, see 47 | \code{\link[=plm]{plm()}} for details,} 48 | 49 | \item{models}{the models used to estimate the variance components 50 | (an alternative to the previous argument),} 51 | 52 | \item{dfcor}{a numeric vector of length 2 indicating which degree 53 | of freedom should be used,} 54 | 55 | \item{index}{the indexes,} 56 | 57 | \item{data}{a \code{data.frame},} 58 | 59 | \item{x}{an \code{ercomp} object,} 60 | 61 | \item{digits}{digits,} 62 | } 63 | \value{ 64 | An object of class \code{"ercomp"}: a list containing \itemize{ 65 | \item \code{sigma2} a named numeric with estimates of the variance 66 | components, \item \code{theta} contains the parameter(s) used for 67 | the transformation of the variables: For a one-way model, a 68 | numeric corresponding to the selected effect (individual or 69 | time); for a two-ways model a list of length 3 with the 70 | parameters. In case of a balanced model, the numeric has length 71 | 1 while for an unbalanced model, the numerics' length equal the 72 | number of observations. } 73 | } 74 | \description{ 75 | This function enables the estimation of the variance components of a panel 76 | model. 77 | } 78 | \examples{ 79 | 80 | data("Produc", package = "plm") 81 | # an example of the formula method 82 | ercomp(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc, 83 | method = "walhus", effect = "time") 84 | # same with the plm method 85 | z <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, 86 | data = Produc, random.method = "walhus", 87 | effect = "time", model = "random") 88 | ercomp(z) 89 | # a two-ways model 90 | ercomp(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc, 91 | method = "amemiya", effect = "twoways") 92 | 93 | } 94 | \references{ 95 | \insertRef{AMEM:71}{plm} 96 | 97 | \insertRef{NERLO:71}{plm} 98 | 99 | \insertRef{SWAM:AROR:72}{plm} 100 | 101 | \insertRef{WALL:HUSS:69}{plm} 102 | } 103 | \seealso{ 104 | \code{\link[=plm]{plm()}} where the estimates of the variance components are 105 | used if a random effects model is estimated 106 | } 107 | \author{ 108 | Yves Croissant 109 | } 110 | \keyword{regression} 111 | -------------------------------------------------------------------------------- /man/has.intercept.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_misc.R 3 | \name{has.intercept} 4 | \alias{has.intercept} 5 | \alias{has.intercept.default} 6 | \alias{has.intercept.formula} 7 | \alias{has.intercept.Formula} 8 | \alias{has.intercept.panelmodel} 9 | \alias{has.intercept.plm} 10 | \title{Check for the presence of an intercept in a formula or in a fitted 11 | model} 12 | \usage{ 13 | has.intercept(object, ...) 14 | 15 | \method{has.intercept}{default}(object, data = NULL, ...) 16 | 17 | \method{has.intercept}{formula}(object, data = NULL, ...) 18 | 19 | \method{has.intercept}{Formula}(object, rhs = NULL, data = NULL, ...) 20 | 21 | \method{has.intercept}{panelmodel}(object, ...) 22 | 23 | \method{has.intercept}{plm}(object, rhs = 1L, ...) 24 | } 25 | \arguments{ 26 | \item{object}{a \code{formula}, a \code{Formula} or a fitted model (of class 27 | \code{plm} or \code{panelmodel}),} 28 | 29 | \item{\dots}{further arguments.} 30 | 31 | \item{data}{default is \code{NULL} and only needs to be changes to a data set if 32 | the formula contains a dot (\code{.}) to allow evaluation of the dot,} 33 | 34 | \item{rhs}{an integer (length > 1 is possible), indicating the parts of right 35 | hand sides of the formula to be evaluated for the presence of an 36 | intercept or \code{NULL} for all parts of the right hand side 37 | (relevant for the \code{Formula} and the \code{plm} methods),} 38 | } 39 | \value{ 40 | a logical 41 | } 42 | \description{ 43 | The presence of an intercept is checked using the formula which is 44 | either provided as the argument of the function or extracted from 45 | a fitted model. 46 | } 47 | -------------------------------------------------------------------------------- /man/index.plm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_pdata.frame.R 3 | \name{index.plm} 4 | \alias{index.plm} 5 | \alias{index} 6 | \alias{index.pindex} 7 | \alias{index.pdata.frame} 8 | \alias{index.pseries} 9 | \alias{index.panelmodel} 10 | \title{Extract the indexes of panel data} 11 | \usage{ 12 | \method{index}{pindex}(x, which = NULL, ...) 13 | 14 | \method{index}{pdata.frame}(x, which = NULL, ...) 15 | 16 | \method{index}{pseries}(x, which = NULL, ...) 17 | 18 | \method{index}{panelmodel}(x, which = NULL, ...) 19 | } 20 | \arguments{ 21 | \item{x}{an object of class \code{"pindex"}, \code{"pdata.frame"}, 22 | \code{"pseries"} or \code{"panelmodel"},} 23 | 24 | \item{which}{the index(es) to be extracted (see details),} 25 | 26 | \item{\dots}{further arguments.} 27 | } 28 | \value{ 29 | A vector or an object of class \code{c("pindex","data.frame")} 30 | containing either one index, individual and time index, or (any 31 | combination of) individual, time and group indexes. 32 | } 33 | \description{ 34 | This function extracts the information about the structure of the 35 | individual and time dimensions of panel data. Grouping information 36 | can also be extracted if the panel data were created with a 37 | grouping variable. 38 | } 39 | \details{ 40 | Panel data are stored in a \code{"pdata.frame"} which has an \code{"index"} 41 | attribute. Fitted models in \code{"plm"} have a \code{"model"} element which 42 | is also a \code{"pdata.frame"} and therefore also has an \code{"index"} 43 | attribute. Finally, each series, once extracted from a 44 | \code{"pdata.frame"}, becomes of class \code{"pseries"}, which also has this 45 | \code{"index"} attribute. \code{"index"} methods are available for all these 46 | objects. The argument \code{"which"} indicates which index should be 47 | extracted. If \code{which = NULL}, all indexes are extracted. \code{"which"} 48 | can also be a vector of length 1, 2, or 3 (3 only if the pdata 49 | frame was constructed with an additional group index) containing 50 | either characters (the names of the individual variable and/or of 51 | the time variable and/or the group variable or \code{"id"} and \code{"time"}) 52 | and \code{"group"} or integers (1 for the individual index, 2 for the 53 | time index, and 3 for the group index (the latter only if the pdata 54 | frame was constructed with such).) 55 | } 56 | \examples{ 57 | 58 | data("Grunfeld", package = "plm") 59 | Gr <- pdata.frame(Grunfeld, index = c("firm", "year")) 60 | m <- plm(inv ~ value + capital, data = Gr) 61 | index(Gr, "firm") 62 | index(Gr, "time") 63 | index(Gr$inv, c(2, 1)) 64 | index(m, "id") 65 | 66 | # with additional group index 67 | data("Produc", package = "plm") 68 | pProduc <- pdata.frame(Produc, index = c("state", "year", "region")) 69 | index(pProduc, 3) 70 | index(pProduc, "region") 71 | index(pProduc, "group") 72 | 73 | } 74 | \seealso{ 75 | \code{\link[=pdata.frame]{pdata.frame()}}, \code{\link[=plm]{plm()}} 76 | } 77 | \author{ 78 | Yves Croissant 79 | } 80 | \keyword{attribute} 81 | -------------------------------------------------------------------------------- /man/is.pbalanced.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_pdata.frame.R 3 | \name{is.pbalanced} 4 | \alias{is.pbalanced} 5 | \alias{is.pbalanced.default} 6 | \alias{is.pbalanced.data.frame} 7 | \alias{is.pbalanced.pdata.frame} 8 | \alias{is.pbalanced.pseries} 9 | \alias{is.pbalanced.pggls} 10 | \alias{is.pbalanced.pcce} 11 | \alias{is.pbalanced.pmg} 12 | \alias{is.pbalanced.pgmm} 13 | \alias{is.pbalanced.panelmodel} 14 | \title{Check if data are balanced} 15 | \usage{ 16 | is.pbalanced(x, ...) 17 | 18 | \method{is.pbalanced}{default}(x, y, ...) 19 | 20 | \method{is.pbalanced}{data.frame}(x, index = NULL, ...) 21 | 22 | \method{is.pbalanced}{pdata.frame}(x, ...) 23 | 24 | \method{is.pbalanced}{pseries}(x, ...) 25 | 26 | \method{is.pbalanced}{pggls}(x, ...) 27 | 28 | \method{is.pbalanced}{pcce}(x, ...) 29 | 30 | \method{is.pbalanced}{pmg}(x, ...) 31 | 32 | \method{is.pbalanced}{pgmm}(x, ...) 33 | 34 | \method{is.pbalanced}{panelmodel}(x, ...) 35 | } 36 | \arguments{ 37 | \item{x}{an object of class \code{pdata.frame}, \code{data.frame}, 38 | \code{pseries}, \code{panelmodel}, or \code{pgmm},} 39 | 40 | \item{\dots}{further arguments.} 41 | 42 | \item{y}{(only in default method) the time index variable (2nd index 43 | variable),} 44 | 45 | \item{index}{only relevant for \code{data.frame} interface; if 46 | \code{NULL}, the first two columns of the data.frame are 47 | assumed to be the index variables; if not \code{NULL}, both 48 | dimensions ('individual', 'time') need to be specified by 49 | \code{index} as character of length 2 for data frames, for 50 | further details see \code{\link[=pdata.frame]{pdata.frame()}},} 51 | } 52 | \value{ 53 | A logical indicating whether the data associated with 54 | object \code{x} are balanced (\code{TRUE}) or not 55 | (\code{FALSE}). 56 | } 57 | \description{ 58 | This function checks if the data are balanced, i.e., if each individual has 59 | the same time periods 60 | } 61 | \details{ 62 | Balanced data are data for which each individual has the same time periods. 63 | The returned values of the \code{is.pbalanced(object)} methods are identical 64 | to \code{pdim(object)$balanced}. \code{is.pbalanced} is provided as a short 65 | cut and is faster than \code{pdim(object)$balanced} because it avoids those 66 | computations performed by \code{pdim} which are unnecessary to determine the 67 | balancedness of the data. 68 | } 69 | \examples{ 70 | 71 | # take balanced data and make it unbalanced 72 | # by deletion of 2nd row (2nd time period for first individual) 73 | data("Grunfeld", package = "plm") 74 | Grunfeld_missing_period <- Grunfeld[-2, ] 75 | is.pbalanced(Grunfeld_missing_period) # check if balanced: FALSE 76 | pdim(Grunfeld_missing_period)$balanced # same 77 | 78 | # pdata.frame interface 79 | pGrunfeld_missing_period <- pdata.frame(Grunfeld_missing_period) 80 | is.pbalanced(Grunfeld_missing_period) 81 | 82 | # pseries interface 83 | is.pbalanced(pGrunfeld_missing_period$inv) 84 | 85 | } 86 | \seealso{ 87 | \code{\link[=punbalancedness]{punbalancedness()}} for two measures of 88 | unbalancedness, \code{\link[=make.pbalanced]{make.pbalanced()}} to make data 89 | balanced; \code{\link[=is.pconsecutive]{is.pconsecutive()}} to check if data are 90 | consecutive; \code{\link[=make.pconsecutive]{make.pconsecutive()}} to make data 91 | consecutive (and, optionally, also balanced).\cr 92 | \code{\link[=pdim]{pdim()}} to check the dimensions of a 'pdata.frame' 93 | (and other objects), \code{\link[=pvar]{pvar()}} to check for individual 94 | and time variation of a 'pdata.frame' (and other objects), 95 | \code{\link[=pseries]{pseries()}}, \code{\link[=data.frame]{data.frame()}}, 96 | \code{\link[=pdata.frame]{pdata.frame()}}. 97 | } 98 | \keyword{attribute} 99 | -------------------------------------------------------------------------------- /man/is.pseries.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_pdata.frame.R 3 | \name{is.pseries} 4 | \alias{is.pseries} 5 | \title{Check if an object is a pseries} 6 | \usage{ 7 | is.pseries(object) 8 | } 9 | \arguments{ 10 | \item{object}{object to be checked for pseries features} 11 | } 12 | \value{ 13 | A logical indicating whether the object is a pseries (\code{TRUE}) 14 | or not (\code{FALSE}). 15 | } 16 | \description{ 17 | This function checks if an object qualifies as a pseries 18 | } 19 | \details{ 20 | A \code{"pseries"} is a wrapper around a "basic class" (numeric, factor, 21 | logical, character, or complex). 22 | 23 | To qualify as a pseries, an object needs to have the following 24 | features: 25 | \itemize{ 26 | \item class contains \code{"pseries"} and there are at least two classes 27 | (\code{"pseries"} and the basic class), 28 | \item have an appropriate index attribute (defines the panel 29 | structure), 30 | \item any of \code{is.numeric}, \code{is.factor}, \code{is.logical}, \code{is.character}, 31 | \code{is.complex} is \code{TRUE}. 32 | } 33 | } 34 | \examples{ 35 | 36 | # Create a pdata.frame and extract a series, which becomes a pseries 37 | data("EmplUK", package = "plm") 38 | Em <- pdata.frame(EmplUK) 39 | z <- Em$output 40 | 41 | class(z) # pseries as indicated by class 42 | is.pseries(z) # and confirmed by check 43 | 44 | # destroy index of pseries and re-check 45 | attr(z, "index") <- NA 46 | is.pseries(z) # now FALSE 47 | 48 | } 49 | \seealso{ 50 | \code{\link[=pseries]{pseries()}} for some computations on pseries and some 51 | further links. 52 | } 53 | \keyword{attribute} 54 | -------------------------------------------------------------------------------- /man/lag.plm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_transformations.R 3 | \name{lag.plm} 4 | \alias{lag.plm} 5 | \alias{lag} 6 | \alias{lead} 7 | \alias{diff} 8 | \alias{lag.pseries} 9 | \alias{lead.pseries} 10 | \alias{diff.pseries} 11 | \title{lag, lead, and diff for panel data} 12 | \usage{ 13 | lead(x, k = 1L, ...) 14 | 15 | \method{lag}{pseries}(x, k = 1L, shift = c("time", "row"), ...) 16 | 17 | \method{lead}{pseries}(x, k = 1L, shift = c("time", "row"), ...) 18 | 19 | \method{diff}{pseries}(x, lag = 1L, shift = c("time", "row"), ...) 20 | } 21 | \arguments{ 22 | \item{x}{a \code{pseries} object,} 23 | 24 | \item{k}{an integer, the number of lags for the \code{lag} and \code{lead} 25 | methods (can also be negative). For the \code{lag} method, a 26 | positive (negative) \code{k} gives lagged (leading) values. For the 27 | \code{lead} method, a positive (negative) \code{k} gives leading (lagged) 28 | values, thus, \code{lag(x, k = -1L)} yields the same as \code{lead(x, k = 1L)}. 29 | If \code{k} is an integer with length > 1 (\code{k = c(k1, k2, ...)}), a 30 | \code{matrix} with multiple lagged \code{pseries} is returned,} 31 | 32 | \item{...}{further arguments (currently none evaluated).} 33 | 34 | \item{shift}{character, either \code{"time"} (default) or \code{"row"} 35 | determining how the shifting in the \code{lag}/\code{lead}/\code{diff} 36 | functions is performed (see Details and Examples).} 37 | 38 | \item{lag}{integer, the number of lags for the \code{diff} method, can also be of 39 | length > 1 (see argument \code{k}) (only non--negative values in 40 | argument \code{lag} are allowed for \code{diff}),} 41 | } 42 | \value{ 43 | \itemize{ 44 | \item An object of class \code{pseries}, if the argument specifying the lag 45 | has length 1 (argument \code{k} in functions \code{lag} and \code{lead}, 46 | argument \code{lag} in function \code{diff}). 47 | \item A matrix containing the various series in its columns, if the 48 | argument specifying the lag has length > 1. 49 | } 50 | } 51 | \description{ 52 | lag, lead, and diff functions for class pseries. 53 | } 54 | \details{ 55 | This set of functions perform lagging, leading (lagging in the 56 | opposite direction), and differencing operations on \code{pseries} 57 | objects, i. e., they take the panel structure of the data into 58 | account by performing the operations per individual. 59 | 60 | Argument \code{shift} controls the shifting of observations to be used 61 | by methods \code{lag}, \code{lead}, and \code{diff}: 62 | \itemize{ 63 | \item \code{shift = "time"} (default): Methods respect the 64 | numerical value in the time dimension of the index. The time 65 | dimension needs to be interpretable as a sequence t, t+1, t+2, 66 | \ldots{} where t is an integer (from a technical viewpoint, 67 | \code{as.numeric(as.character(index(your_pdata.frame)[[2]]))} needs to 68 | result in a meaningful integer). 69 | \item \verb{shift = "row": }Methods perform the shifting operation based 70 | solely on the "physical position" of the observations, 71 | i.e., neighbouring rows are shifted per individual. The value in the 72 | time index is not relevant in this case. 73 | } 74 | 75 | For consecutive time periods per individual, a switch of shifting 76 | behaviour results in no difference. Different return values will 77 | occur for non-consecutive time periods per individual 78 | ("holes in time"), see also Examples. 79 | } 80 | \note{ 81 | The sign of \code{k} in \code{lag.pseries} results in inverse behaviour 82 | compared to \code{\link[stats:lag]{stats::lag()}} and \code{\link[zoo:lag.zoo]{zoo::lag.zoo()}}. 83 | } 84 | \examples{ 85 | 86 | # First, create a pdata.frame 87 | data("EmplUK", package = "plm") 88 | Em <- pdata.frame(EmplUK) 89 | 90 | # Then extract a series, which becomes additionally a pseries 91 | z <- Em$output 92 | class(z) 93 | 94 | # compute the first and third lag, and the difference lagged twice 95 | lag(z) 96 | lag(z, 3L) 97 | diff(z, 2L) 98 | 99 | # compute negative lags (= leading values) 100 | lag(z, -1L) 101 | lead(z, 1L) # same as line above 102 | identical(lead(z, 1L), lag(z, -1L)) # TRUE 103 | 104 | # compute more than one lag and diff at once (matrix returned) 105 | lag(z, c(1L,2L)) 106 | diff(z, c(1L,2L)) 107 | 108 | ## demonstrate behaviour of shift = "time" vs. shift = "row" 109 | # delete 2nd time period for first individual (1978 is missing (not NA)): 110 | Em_hole <- Em[-2L, ] 111 | is.pconsecutive(Em_hole) # check: non-consecutive for 1st individual now 112 | 113 | # original non-consecutive data: 114 | head(Em_hole$emp, 10) 115 | # for shift = "time", 1-1979 contains the value of former 1-1977 (2 periods lagged): 116 | head(lag(Em_hole$emp, k = 2L, shift = "time"), 10L) 117 | # for shift = "row", 1-1979 contains NA (2 rows lagged (and no entry for 1976): 118 | head(lag(Em_hole$emp, k = 2L, shift = "row"), 10L) 119 | 120 | } 121 | \seealso{ 122 | To check if the time periods are consecutive per 123 | individual, see \code{\link[=is.pconsecutive]{is.pconsecutive()}}. 124 | 125 | For further function for 'pseries' objects: \code{\link[=between]{between()}}, 126 | \link[=between]{Between()}, \code{\link[=Within]{Within()}}, \code{\link[=summary.pseries]{summary.pseries()}}, 127 | \code{\link[=print.summary.pseries]{print.summary.pseries()}}, \code{\link[=as.matrix.pseries]{as.matrix.pseries()}}. 128 | } 129 | \author{ 130 | Yves Croissant and Kevin Tappe 131 | } 132 | \keyword{classes} 133 | -------------------------------------------------------------------------------- /man/make.dummies.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_misc.R 3 | \name{make.dummies} 4 | \alias{make.dummies} 5 | \alias{make.dummies.default} 6 | \alias{make.dummies.data.frame} 7 | \alias{make.dummies.pdata.frame} 8 | \title{Create a Dummy Matrix} 9 | \usage{ 10 | make.dummies(x, ...) 11 | 12 | \method{make.dummies}{default}(x, base = 1L, base.add = TRUE, ...) 13 | 14 | \method{make.dummies}{data.frame}(x, col, base = 1L, base.add = TRUE, ...) 15 | 16 | \method{make.dummies}{pdata.frame}(x, col, base = 1L, base.add = TRUE, ...) 17 | } 18 | \arguments{ 19 | \item{x}{a factor from which the dummies are created (x is coerced to 20 | factor if not yet a factor) for the default method or a data 21 | data frame/pdata.frame for the respective method.} 22 | 23 | \item{\dots}{further arguments.} 24 | 25 | \item{base}{integer or character, specifies the reference level (base), if 26 | integer it refers to position in \code{levels(x)}, if character the name 27 | of a level,} 28 | 29 | \item{base.add}{logical, if \code{TRUE} the reference level (base) is added 30 | to the return value as first column, if \code{FALSE} the reference 31 | level is not included.} 32 | 33 | \item{col}{character (only for the data frame and pdata.frame methods), to 34 | specify the column which is used to derive the dummies from,} 35 | } 36 | \value{ 37 | For the default method, a matrix containing the contrast-coded 38 | dummies (treatment coding), 39 | dimensions are n x n where \code{n = length(levels(x))} if argument 40 | \code{base.add = TRUE} or \code{n = length(levels(x)-1)} if \code{base.add = FALSE}; 41 | for the data frame and pdata.frame method, a data frame or pdata.frame, 42 | respectively, with the dummies appropriately merged to the input as 43 | last columns (column names are derived from the name of the column 44 | used to create the dummies and its levels). 45 | } 46 | \description{ 47 | Contrast-coded dummy matrix (treatment coding) created from a factor 48 | } 49 | \details{ 50 | This function creates a matrix of dummies from the levels of a factor in 51 | treatment coding. In model estimations, it is usually preferable to not 52 | create the dummy matrix prior to estimation but to simply specify a factor 53 | in the formula and let the estimation function handle the creation of the 54 | dummies. 55 | 56 | This function is merely a convenience wrapper around \code{stats::contr.treatment} 57 | to ease the dummy matrix creation process shall the dummy matrix be explicitly 58 | required. See Examples for a use case in LSDV (least squares dummy variable) 59 | model estimation. 60 | 61 | The default method uses a factor as main input (or something coercible to a 62 | factor) to derive the dummy matrix from. Methods for data frame and pdata.frame 63 | are available as well and have the additional argument \code{col} to specify the 64 | the column from which the dummies are created; both methods merge the dummy 65 | matrix to the data frame/pdata.frame yielding a ready-to-use data set. 66 | See also Examples for use cases. 67 | } 68 | \examples{ 69 | library(plm) 70 | data("Grunfeld", package = "plm") 71 | Grunfeld <- Grunfeld[1:100, ] # reduce data set (down to 5 firms) 72 | 73 | ## default method 74 | make.dummies(Grunfeld$firm) # gives 5 x 5 matrix (5 firms, base level incl.) 75 | make.dummies(Grunfeld$firm, base = 2L, base.add = FALSE) # gives 5 x 4 matrix 76 | 77 | ## data frame method 78 | Grun.dummies <- make.dummies(Grunfeld, col = "firm") 79 | 80 | ## pdata.frame method 81 | pGrun <- pdata.frame(Grunfeld) 82 | pGrun.dummies <- make.dummies(pGrun, col = "firm") 83 | 84 | ## Model estimation: 85 | ## estimate within model (individual/firm effects) and LSDV models (firm dummies) 86 | # within model: 87 | plm(inv ~ value + capital, data = pGrun, model = "within") 88 | 89 | ## LSDV with user-created dummies by make.dummies: 90 | form_dummies <- paste0("firm", c(1:5), collapse = "+") 91 | form_dummies <- formula(paste0("inv ~ value + capital + ", form_dummies)) 92 | plm(form_dummies, data = pGrun.dummies, model = "pooling") # last dummy is dropped 93 | 94 | # LSDV via factor(year) -> let estimation function generate dummies: 95 | plm(inv ~ value + capital + factor(firm), data = pGrun, model = "pooling") 96 | } 97 | \seealso{ 98 | \code{\link[stats:contrast]{stats::contr.treatment()}}, \code{\link[stats:contrasts]{stats::contrasts()}} 99 | } 100 | \author{ 101 | Kevin Tappe 102 | } 103 | \keyword{manip} 104 | -------------------------------------------------------------------------------- /man/model.frame.pdata.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_model.extract.R 3 | \name{model.frame.pdata.frame} 4 | \alias{model.frame.pdata.frame} 5 | \alias{formula.pdata.frame} 6 | \alias{model.matrix.plm} 7 | \alias{model.matrix.pdata.frame} 8 | \title{model.frame and model.matrix for panel data} 9 | \usage{ 10 | \method{model.frame}{pdata.frame}( 11 | formula, 12 | data = NULL, 13 | ..., 14 | lhs = NULL, 15 | rhs = NULL, 16 | dot = "previous" 17 | ) 18 | 19 | \method{formula}{pdata.frame}(x, ...) 20 | 21 | \method{model.matrix}{plm}(object, ...) 22 | 23 | \method{model.matrix}{pdata.frame}( 24 | object, 25 | model = c("pooling", "within", "Between", "Sum", "between", "mean", "random", "fd"), 26 | effect = c("individual", "time", "twoways", "nested"), 27 | rhs = 1, 28 | theta = NULL, 29 | cstcovar.rm = NULL, 30 | ... 31 | ) 32 | } 33 | \arguments{ 34 | \item{data}{a \code{formula}, see \strong{Details},} 35 | 36 | \item{\dots}{further arguments.} 37 | 38 | \item{lhs}{inherited from package \code{\link[Formula:Formula]{Formula::Formula()}} (see 39 | there),} 40 | 41 | \item{rhs}{inherited from package \code{\link[Formula:Formula]{Formula::Formula()}} (see 42 | there),} 43 | 44 | \item{dot}{inherited from package \code{\link[Formula:Formula]{Formula::Formula()}} (see 45 | there),} 46 | 47 | \item{x}{a \code{model.frame}} 48 | 49 | \item{object, formula}{an object of class \code{"pdata.frame"} or an 50 | estimated model object of class \code{"plm"},} 51 | 52 | \item{model}{one of \code{"pooling"}, \code{"within"}, \code{"Sum"}, \code{"Between"}, 53 | \code{"between"}, \verb{"random",} \code{"fd"} and \code{"ht"},} 54 | 55 | \item{effect}{the effects introduced in the model, one of 56 | \code{"individual"}, \code{"time"}, \code{"twoways"} or \code{"nested"},} 57 | 58 | \item{theta}{the parameter for the transformation if \code{model = "random"},} 59 | 60 | \item{cstcovar.rm}{remove the constant columns, one of \verb{"none", "intercept", "covariates", "all")},} 61 | } 62 | \value{ 63 | The \code{model.frame} methods return a \code{pdata.frame}.\cr The 64 | \code{model.matrix} methods return a \code{matrix}. 65 | } 66 | \description{ 67 | Methods to create model frame and model matrix for panel data. 68 | } 69 | \details{ 70 | The \code{lhs} and \code{rhs} arguments are inherited from \code{Formula}, see 71 | there for more details.\cr The \code{model.frame} methods return a 72 | \code{pdata.frame} object suitable as an input to plm's 73 | \code{model.matrix}.\cr The \code{model.matrix} methods builds a model matrix 74 | with transformations performed as specified by the \code{model} and 75 | \code{effect} arguments (and \code{theta} if \code{model = "random"} is 76 | requested), in this case the supplied \code{data} argument should be a 77 | model frame created by plm's \code{model.frame} method. If not, it is 78 | tried to construct the model frame from the data. Constructing the 79 | model frame first ensures proper \code{NA} handling, see \strong{Examples}. 80 | } 81 | \examples{ 82 | 83 | # First, make a pdata.frame 84 | data("Grunfeld", package = "plm") 85 | pGrunfeld <- pdata.frame(Grunfeld) 86 | 87 | # then make a model frame from a formula and a pdata.frame 88 | form <- inv ~ value 89 | mf <- model.frame(pGrunfeld, form) 90 | 91 | # then construct the (transformed) model matrix (design matrix) 92 | # from model frame 93 | modmat <- model.matrix(mf, model = "within") 94 | 95 | ## retrieve model frame and model matrix from an estimated plm object 96 | fe_model <- plm(form, data = pGrunfeld, model = "within") 97 | model.frame(fe_model) 98 | model.matrix(fe_model) 99 | 100 | # same as constructed before 101 | all.equal(mf, model.frame(fe_model), check.attributes = FALSE) # TRUE 102 | all.equal(modmat, model.matrix(fe_model), check.attributes = FALSE) # TRUE 103 | 104 | } 105 | \seealso{ 106 | \code{\link[=pmodel.response]{pmodel.response()}} for (transformed) response 107 | variable.\cr \code{\link[Formula:Formula]{Formula::Formula()}} from package \code{Formula}, 108 | especially for the \code{lhs} and \code{rhs} arguments. 109 | } 110 | \author{ 111 | Yves Croissant 112 | } 113 | \keyword{classes} 114 | -------------------------------------------------------------------------------- /man/mtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_gmm.R 3 | \name{mtest} 4 | \alias{mtest} 5 | \alias{mtest.pgmm} 6 | \title{Arellano--Bond Test of Serial Correlation} 7 | \usage{ 8 | mtest(object, ...) 9 | 10 | \method{mtest}{pgmm}(object, order = 1L, vcov = NULL, ...) 11 | } 12 | \arguments{ 13 | \item{object}{an object of class \code{"pgmm"},} 14 | 15 | \item{\dots}{further arguments (currently unused).} 16 | 17 | \item{order}{integer: the order of the serial correlation,} 18 | 19 | \item{vcov}{a matrix of covariance for the coefficients or a function to 20 | compute it,} 21 | } 22 | \value{ 23 | An object of class \code{"htest"}. 24 | } 25 | \description{ 26 | Test of serial correlation for models estimated by GMM 27 | } 28 | \details{ 29 | The Arellano--Bond test is a test of correlation based on the residuals of 30 | the estimation. By default, the computation is done with the standard 31 | covariance matrix of the coefficients. A robust estimator of a 32 | covariance matrix can be supplied with the \code{vcov} argument. 33 | 34 | Note that \code{mtest} computes like DPD for Ox and xtabond do, i.e., uses for two-steps 35 | models the one-step model's residuals which were used to construct the efficient 36 | two-steps estimator, see \insertCite{DOOR:AREL:BOND:12}{plm}, p. 32, footnote 7; 37 | As noted by \insertCite{AREL:BOND:91}{plm} (p. 282), the m statistic is rather 38 | flexible and can be defined with any consistent GMM estimator which gives leeway 39 | for implementation, but the test's asymptotic power depends on the estimator's efficiency. 40 | \insertCite{AREL:BOND:91}{plm} (see their footnote 9) used 41 | DPD98 for Gauss (\insertCite{AREL:BOND:98}{plm}) as did 42 | \insertCite{WIND:05}{plm} (see footnote 10) for the basis of his 43 | covariance correction, both with a slightly different implementation. 44 | Hence some results for \code{mtest} with two-step models diverge from original papers, 45 | see examples below. 46 | } 47 | \examples{ 48 | data("EmplUK", package = "plm") 49 | # Arellano/Bond 1991, Table 4, column (a1) 50 | ab.a1 <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1) 51 | + lag(log(capital), 0:2) + lag(log(output), 0:2) | lag(log(emp), 2:99), 52 | data = EmplUK, effect = "twoways", model = "onestep") 53 | mtest(ab.a1, 1L) 54 | mtest(ab.a1, 2L, vcov = vcovHC) 55 | 56 | # Windmeijer (2005), table 2, onestep with corrected std. err 57 | ab.b.onestep <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1) 58 | + log(capital) + lag(log(output), 0:1) | lag(log(emp), 2:99), 59 | data = EmplUK, effect = "twoways", model = "onestep") 60 | mtest(ab.b.onestep, 1L, vcov = vcovHC) 61 | mtest(ab.b.onestep, 2L, vcov = vcovHC) 62 | 63 | # Arellano/Bond 1991, Table 4, column (a2) 64 | ab.a2 <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1) 65 | + lag(log(capital), 0:2) + lag(log(output), 0:2) | lag(log(emp), 2:99), 66 | data = EmplUK, effect = "twoways", model = "twosteps") 67 | mtest(ab.a2, 1L) 68 | mtest(ab.a2, 2L) # while a la Arellano/Bond (1991) -0.434 69 | } 70 | \references{ 71 | \insertAllCited{} 72 | } 73 | \seealso{ 74 | \code{\link[=pgmm]{pgmm()}}, \code{\link[=vcovHC.pgmm]{vcovHC.pgmm()}} 75 | } 76 | \author{ 77 | Yves Croissant 78 | } 79 | \keyword{htest} 80 | -------------------------------------------------------------------------------- /man/nobs.plm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_methods.R 3 | \name{nobs.plm} 4 | \alias{nobs.plm} 5 | \alias{nobs} 6 | \alias{nobs.panelmodel} 7 | \alias{nobs.pgmm} 8 | \title{Extract Total Number of Observations Used in Estimated Panelmodel} 9 | \usage{ 10 | \method{nobs}{panelmodel}(object, ...) 11 | 12 | \method{nobs}{pgmm}(object, ...) 13 | } 14 | \arguments{ 15 | \item{object}{a \code{panelmodel} object for which the number of 16 | total observations is to be extracted,} 17 | 18 | \item{\dots}{further arguments.} 19 | } 20 | \value{ 21 | A single number, normally an integer. 22 | } 23 | \description{ 24 | This function extracts the total number of 'observations' from a 25 | fitted panel model. 26 | } 27 | \details{ 28 | The number of observations is usually the length of the residuals 29 | vector. Thus, \code{nobs} gives the number of observations actually 30 | used by the estimation procedure. It is not necessarily the number 31 | of observations of the model frame (number of rows in the model 32 | frame), because sometimes the model frame is further reduced by the 33 | estimation procedure. This is, e.g., the case for first--difference 34 | models estimated by \code{plm(..., model = "fd")} where the model 35 | frame does not yet contain the differences (see also 36 | \strong{Examples}). 37 | } 38 | \examples{ 39 | 40 | # estimate a panelmodel 41 | data("Produc", package = "plm") 42 | z <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp,data=Produc, 43 | model="random", subset = gsp > 5000) 44 | 45 | nobs(z) # total observations used in estimation 46 | pdim(z)$nT$N # same information 47 | pdim(z) # more information about the dimensions (no. of individuals and time periods) 48 | 49 | # illustrate difference between nobs and pdim for first-difference model 50 | data("Grunfeld", package = "plm") 51 | fdmod <- plm(inv ~ value + capital, data = Grunfeld, model = "fd") 52 | nobs(fdmod) # 190 53 | pdim(fdmod)$nT$N # 200 54 | 55 | } 56 | \seealso{ 57 | \code{\link[=pdim]{pdim()}} 58 | } 59 | \keyword{attribute} 60 | -------------------------------------------------------------------------------- /man/pFtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_general.R 3 | \name{pFtest} 4 | \alias{pFtest} 5 | \alias{pFtest.formula} 6 | \alias{pFtest.plm} 7 | \title{F Test for Individual and/or Time Effects} 8 | \usage{ 9 | pFtest(x, ...) 10 | 11 | \method{pFtest}{formula}(x, data, ...) 12 | 13 | \method{pFtest}{plm}(x, z, ...) 14 | } 15 | \arguments{ 16 | \item{x}{an object of class \code{"plm"} or of class \code{"formula"},} 17 | 18 | \item{\dots}{further arguments.} 19 | 20 | \item{data}{a \code{data.frame},} 21 | 22 | \item{z}{an object of class \code{"plm"},} 23 | } 24 | \value{ 25 | An object of class \code{"htest"}. 26 | } 27 | \description{ 28 | Test of individual and/or time effects based on the comparison of the 29 | \code{within} and the \code{pooling} model. 30 | } 31 | \details{ 32 | For the \code{plm} method, the argument of this function is two \code{plm} 33 | objects, the first being a within model, the second a pooling 34 | model. The effects tested are either individual, time or twoways, 35 | depending on the effects introduced in the within model. 36 | } 37 | \examples{ 38 | 39 | data("Grunfeld", package="plm") 40 | gp <- plm(inv ~ value + capital, data = Grunfeld, model = "pooling") 41 | gi <- plm(inv ~ value + capital, data = Grunfeld, 42 | effect = "individual", model = "within") 43 | gt <- plm(inv ~ value + capital, data = Grunfeld, 44 | effect = "time", model = "within") 45 | gd <- plm(inv ~ value + capital, data = Grunfeld, 46 | effect = "twoways", model = "within") 47 | pFtest(gi, gp) 48 | pFtest(gt, gp) 49 | pFtest(gd, gp) 50 | pFtest(inv ~ value + capital, data = Grunfeld, effect = "twoways") 51 | 52 | } 53 | \seealso{ 54 | \code{\link[=plmtest]{plmtest()}} for Lagrange multiplier tests of individuals 55 | and/or time effects. 56 | } 57 | \author{ 58 | Yves Croissant 59 | } 60 | \keyword{htest} 61 | -------------------------------------------------------------------------------- /man/pbgtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_serial.R 3 | \name{pbgtest} 4 | \alias{pbgtest} 5 | \alias{pbgtest.panelmodel} 6 | \alias{pbgtest.formula} 7 | \title{Breusch--Godfrey Test for Panel Models} 8 | \usage{ 9 | pbgtest(x, ...) 10 | 11 | \method{pbgtest}{panelmodel}(x, order = NULL, type = c("Chisq", "F"), ...) 12 | 13 | \method{pbgtest}{formula}( 14 | x, 15 | order = NULL, 16 | type = c("Chisq", "F"), 17 | data, 18 | model = c("pooling", "random", "within"), 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{x}{an object of class \code{"panelmodel"} or of class \code{"formula"},} 24 | 25 | \item{\dots}{further arguments (see \code{\link[lmtest:bgtest]{lmtest::bgtest()}}).} 26 | 27 | \item{order}{an integer indicating the order of serial correlation 28 | to be tested for. \code{NULL} (default) uses the minimum number of 29 | observations over the time dimension (see also section 30 | \strong{Details} below),} 31 | 32 | \item{type}{type of test statistic to be calculated; either 33 | \code{"Chisq"} (default) for the Chi-squared test statistic or \code{"F"} 34 | for the F test statistic,} 35 | 36 | \item{data}{only relevant for formula interface: data set for which 37 | the respective panel model (see \code{model}) is to be evaluated,} 38 | 39 | \item{model}{only relevant for formula interface: compute test 40 | statistic for model \code{pooling} (default), \code{random}, or \code{within}. 41 | When \code{model} is used, the \code{data} argument needs to be passed as 42 | well,} 43 | } 44 | \value{ 45 | An object of class \code{"htest"}. 46 | } 47 | \description{ 48 | Test of serial correlation for (the idiosyncratic component of) the 49 | errors in panel models. 50 | } 51 | \details{ 52 | This Lagrange multiplier test uses the auxiliary model on 53 | (quasi-)demeaned data taken from a model of class \code{plm} which may 54 | be a \code{pooling} (default for formula interface), \code{random} or 55 | \code{within} model. It performs a Breusch--Godfrey test (using \code{bgtest} 56 | from package \CRANpkg{lmtest} on the residuals of the 57 | (quasi-)demeaned model, which should be serially uncorrelated under 58 | the null of no serial correlation in idiosyncratic errors, as 59 | illustrated in \insertCite{WOOL:10;textual}{plm}. The function 60 | takes the demeaned data, estimates the model and calls \code{bgtest}. 61 | 62 | Unlike most other tests for serial correlation in panels, this one 63 | allows to choose the order of correlation to test for. 64 | } 65 | \note{ 66 | The argument \code{order} defaults to the minimum number of 67 | observations over the time dimension, while for 68 | \code{lmtest::bgtest} it defaults to \code{1}. 69 | } 70 | \examples{ 71 | 72 | data("Grunfeld", package = "plm") 73 | g <- plm(inv ~ value + capital, data = Grunfeld, model = "random") 74 | 75 | # panelmodel interface 76 | pbgtest(g) 77 | pbgtest(g, order = 4) 78 | 79 | # formula interface 80 | pbgtest(inv ~ value + capital, data = Grunfeld, model = "random") 81 | 82 | # F test statistic (instead of default type="Chisq") 83 | pbgtest(g, type="F") 84 | pbgtest(inv ~ value + capital, data = Grunfeld, model = "random", type = "F") 85 | 86 | } 87 | \references{ 88 | \insertRef{BREU:78}{plm} 89 | 90 | \insertRef{GODF:78}{plm} 91 | 92 | \insertRef{WOOL:02}{plm} 93 | 94 | \insertRef{WOOL:10}{plm} 95 | 96 | \insertRef{WOOL:13}{plm} 97 | Sec. 12.2, pp. 421--422. 98 | } 99 | \seealso{ 100 | For the original test in package \CRANpkg{lmtest} see 101 | \code{\link[lmtest:bgtest]{lmtest::bgtest()}}. See \code{\link[=pdwtest]{pdwtest()}} for the analogous 102 | panel Durbin--Watson test. See \code{\link[=pbltest]{pbltest()}}, \code{\link[=pbsytest]{pbsytest()}}, 103 | \code{\link[=pwartest]{pwartest()}} and \code{\link[=pwfdtest]{pwfdtest()}} for other serial correlation 104 | tests for panel models. 105 | } 106 | \author{ 107 | Giovanni Millo 108 | } 109 | \keyword{htest} 110 | -------------------------------------------------------------------------------- /man/pbltest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_serial.R 3 | \name{pbltest} 4 | \alias{pbltest} 5 | \alias{pbltest.formula} 6 | \alias{pbltest.plm} 7 | \title{Baltagi and Li Serial Dependence Test For Random Effects Models} 8 | \usage{ 9 | pbltest(x, ...) 10 | 11 | \method{pbltest}{formula}(x, data, alternative = c("twosided", "onesided"), index = NULL, ...) 12 | 13 | \method{pbltest}{plm}(x, alternative = c("twosided", "onesided"), ...) 14 | } 15 | \arguments{ 16 | \item{x}{a model formula or an estimated random--effects model of 17 | class \code{plm} ,} 18 | 19 | \item{\dots}{further arguments.} 20 | 21 | \item{data}{for the formula interface only: a \code{data.frame},} 22 | 23 | \item{alternative}{one of \code{"twosided"}, 24 | \code{"onesided"}. Selects either \eqn{H_A: \rho \neq 0} or 25 | \eqn{H_A: \rho = 0} (i.e., the Normal or the Chi-squared 26 | version of the test),} 27 | 28 | \item{index}{the index of the \code{data.frame},} 29 | } 30 | \value{ 31 | An object of class \code{"htest"}. 32 | } 33 | \description{ 34 | \insertCite{BALT:LI:95;textual}{plm}'s Lagrange multiplier test for 35 | AR(1) or MA(1) idiosyncratic errors in panel models with random 36 | effects. 37 | } 38 | \details{ 39 | This is a Lagrange multiplier test for the null of no serial 40 | correlation, against the alternative of either an AR(1) or a MA(1) 41 | process, in the idiosyncratic component of the error term in a 42 | random effects panel model (as the analytical expression of the 43 | test turns out to be the same under both alternatives, 44 | \insertCite{@see @BALT:LI:95 and @BALT:LI:97}{plm}. The 45 | \code{alternative} argument, defaulting to \code{twosided}, allows testing 46 | for positive serial correlation only, if set to \code{onesided}. 47 | } 48 | \examples{ 49 | 50 | data("Grunfeld", package = "plm") 51 | 52 | # formula interface 53 | pbltest(inv ~ value + capital, data = Grunfeld) 54 | 55 | # plm interface 56 | re_mod <- plm(inv ~ value + capital, data = Grunfeld, model = "random") 57 | pbltest(re_mod) 58 | pbltest(re_mod, alternative = "onesided") 59 | 60 | } 61 | \references{ 62 | \insertRef{BALT:LI:95}{plm} 63 | 64 | \insertRef{BALT:LI:97}{plm} 65 | } 66 | \seealso{ 67 | \code{\link[=pdwtest]{pdwtest()}}, \code{\link[=pbnftest]{pbnftest()}}, \code{\link[=pbgtest]{pbgtest()}}, 68 | \code{\link[=pbsytest]{pbsytest()}}, \code{\link[=pwartest]{pwartest()}} and 69 | \code{\link[=pwfdtest]{pwfdtest()}} for other serial correlation tests for 70 | panel models. 71 | } 72 | \author{ 73 | Giovanni Millo 74 | } 75 | \keyword{htest} 76 | -------------------------------------------------------------------------------- /man/pbnftest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_serial.R 3 | \name{pbnftest} 4 | \alias{pbnftest} 5 | \alias{pbnftest.panelmodel} 6 | \alias{pbnftest.formula} 7 | \title{Modified BNF--Durbin--Watson Test and Baltagi--Wu's LBI Test for Panel 8 | Models} 9 | \usage{ 10 | pbnftest(x, ...) 11 | 12 | \method{pbnftest}{panelmodel}(x, test = c("bnf", "lbi"), ...) 13 | 14 | \method{pbnftest}{formula}( 15 | x, 16 | data, 17 | test = c("bnf", "lbi"), 18 | model = c("pooling", "within", "random"), 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{x}{an object of class \code{"panelmodel"} or of class \code{"formula"},} 24 | 25 | \item{\dots}{only relevant for formula interface: further arguments 26 | to specify the model to test (arguments passed on to plm()), 27 | e.g., \code{effect}.} 28 | 29 | \item{test}{a character indicating the test to be performed, either 30 | \code{"bnf"} or \code{"lbi"} for the (modified) BNF statistic or 31 | Baltagi--Wu's LBI statistic, respectively,} 32 | 33 | \item{data}{a \code{data.frame} (only relevant for formula interface),} 34 | 35 | \item{model}{a character indicating on which type of model the test 36 | shall be performed (\code{"pooling"}, \code{"within"}, \code{"random"}, only 37 | relevant for formula interface),} 38 | } 39 | \value{ 40 | An object of class \code{"htest"}. 41 | } 42 | \description{ 43 | Tests for AR(1) disturbances in panel models. 44 | } 45 | \details{ 46 | The default, \code{test = "bnf"}, gives the (modified) BNF statistic, 47 | the generalised Durbin-Watson statistic for panels. For balanced 48 | and consecutive panels, the reference is 49 | Bhargava/Franzini/Narendranathan (1982). The modified BNF is given 50 | for unbalanced and/or non-consecutive panels (d1 in formula 16 of 51 | \insertCite{BALT:WU:99;textual}{plm}). 52 | 53 | \code{test = "lbi"} yields Baltagi--Wu's LBI statistic 54 | \insertCite{BALT:WU:99}{plm}, the locally best invariant test which 55 | is based on the modified BNF statistic. 56 | 57 | No specific variants of these tests are available for random effect models. 58 | As the within estimator is consistent also under the random effects 59 | assumptions, the test for random effect models is performed by taking the 60 | within residuals. 61 | 62 | No p-values are given for the statistics as their distribution is 63 | quite difficult. \insertCite{BHAR:FRAN:NARE:82;textual}{plm} supply 64 | tabulated bounds for p = 0.05 for the balanced case and consecutive 65 | case. 66 | 67 | For large N, \insertCite{BHAR:FRAN:NARE:82}{plm} suggest it is 68 | sufficient to check whether the BNF statistic is < 2 to test 69 | against positive serial correlation. 70 | } 71 | \examples{ 72 | 73 | data("Grunfeld", package = "plm") 74 | 75 | # formula interface, replicate Baltagi/Wu (1999), table 1, test case A: 76 | data_A <- Grunfeld[!Grunfeld[["year"]] \%in\% c("1943", "1944"), ] 77 | pbnftest(inv ~ value + capital, data = data_A, model = "within") 78 | pbnftest(inv ~ value + capital, data = data_A, test = "lbi", model = "within") 79 | 80 | # replicate Baltagi (2013), p. 101, table 5.1: 81 | re <- plm(inv ~ value + capital, data = Grunfeld, model = "random") 82 | pbnftest(re) 83 | pbnftest(re, test = "lbi") 84 | 85 | } 86 | \references{ 87 | \insertRef{BALT:13}{plm} 88 | 89 | \insertRef{BALT:WU:99}{plm} 90 | 91 | \insertRef{BHAR:FRAN:NARE:82}{plm} 92 | } 93 | \seealso{ 94 | \code{\link[=pdwtest]{pdwtest()}} for the original Durbin--Watson test using 95 | (quasi-)demeaned residuals of the panel model without taking 96 | the panel structure into account. \code{\link[=pbltest]{pbltest()}}, \code{\link[=pbsytest]{pbsytest()}}, 97 | \code{\link[=pwartest]{pwartest()}} and \code{\link[=pwfdtest]{pwfdtest()}} for other serial correlation 98 | tests for panel models. 99 | } 100 | \author{ 101 | Kevin Tappe 102 | } 103 | \keyword{htest} 104 | -------------------------------------------------------------------------------- /man/pcce.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_cce.R 3 | \name{pcce} 4 | \alias{pcce} 5 | \alias{summary.pcce} 6 | \alias{print.summary.pcce} 7 | \alias{residuals.pcce} 8 | \alias{model.matrix.pcce} 9 | \alias{pmodel.response.pcce} 10 | \title{Common Correlated Effects estimators} 11 | \usage{ 12 | pcce( 13 | formula, 14 | data, 15 | subset, 16 | na.action, 17 | model = c("mg", "p"), 18 | index = NULL, 19 | trend = FALSE, 20 | ... 21 | ) 22 | 23 | \method{summary}{pcce}(object, vcov = NULL, ...) 24 | 25 | \method{print}{summary.pcce}( 26 | x, 27 | digits = max(3, getOption("digits") - 2), 28 | width = getOption("width"), 29 | ... 30 | ) 31 | 32 | \method{residuals}{pcce}(object, type = c("defactored", "standard"), ...) 33 | 34 | \method{model.matrix}{pcce}(object, ...) 35 | 36 | \method{pmodel.response}{pcce}(object, ...) 37 | } 38 | \arguments{ 39 | \item{formula}{a symbolic description of the model to be estimated,} 40 | 41 | \item{data}{a \code{data.frame},} 42 | 43 | \item{subset}{see \code{lm},} 44 | 45 | \item{na.action}{see \code{lm},} 46 | 47 | \item{model}{one of \code{"mg"}, \code{"p"}, selects Mean Groups vs. Pooled 48 | CCE model,} 49 | 50 | \item{index}{the indexes, see \code{\link[=pdata.frame]{pdata.frame()}},} 51 | 52 | \item{trend}{logical specifying whether an individual-specific 53 | trend has to be included,} 54 | 55 | \item{\dots}{further arguments.} 56 | 57 | \item{object, x}{an object of class \code{"pcce"},} 58 | 59 | \item{vcov}{a variance-covariance matrix furnished by the user or a function to calculate one,} 60 | 61 | \item{digits}{digits,} 62 | 63 | \item{width}{the maximum length of the lines in the print output,} 64 | 65 | \item{type}{one of \code{"defactored"} or \code{"standard"},} 66 | } 67 | \value{ 68 | An object of class \code{c("pcce", "panelmodel")} containing: 69 | \item{coefficients}{the vector of coefficients,} 70 | \item{residuals}{the vector of (defactored) residuals,} 71 | \item{stdres}{the vector of (raw) residuals,} 72 | \item{tr.model}{the transformed data after projection on H,} 73 | \item{fitted.values}{the vector of fitted values,} 74 | \item{vcov}{the covariance matrix of the coefficients,} 75 | \item{df.residual}{degrees of freedom of the residuals,} 76 | \item{model}{a data.frame containing the variables used for the 77 | estimation,} 78 | \item{call}{the call,} 79 | \item{indcoef}{the matrix of individual coefficients from 80 | separate time series regressions,} 81 | \item{r.squared}{numeric, the R squared.} 82 | } 83 | \description{ 84 | Common Correlated Effects Mean Groups (CCEMG) and Pooled (CCEP) 85 | estimators for panel data with common factors (balanced or 86 | unbalanced) 87 | } 88 | \details{ 89 | \code{pcce} is a function for the estimation of linear panel models by 90 | the Common Correlated Effects Mean Groups or Pooled estimator, 91 | consistent under the hypothesis of unobserved common factors and 92 | idiosyncratic factor loadings. The CCE estimator works by 93 | augmenting the model by cross-sectional averages of the dependent 94 | variable and regressors in order to account for the common factors, 95 | and adding individual intercepts and possibly trends. 96 | } 97 | \examples{ 98 | 99 | data("Produc", package = "plm") 100 | ccepmod <- pcce(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc, model="p") 101 | summary(ccepmod) 102 | summary(ccepmod, vcov = vcovHC) # use argument vcov for robust std. errors 103 | 104 | ccemgmod <- pcce(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc, model="mg") 105 | summary(ccemgmod) 106 | 107 | } 108 | \references{ 109 | \insertRef{kappesyam11}{plm} 110 | 111 | \insertRef{HOLL:PESA:YAMA:10}{plm} 112 | } 113 | \author{ 114 | Giovanni Millo 115 | } 116 | \keyword{regression} 117 | -------------------------------------------------------------------------------- /man/pdim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_pdata.frame.R 3 | \name{pdim} 4 | \alias{pdim} 5 | \alias{pdim.default} 6 | \alias{pdim.data.frame} 7 | \alias{pdim.pdata.frame} 8 | \alias{pdim.pseries} 9 | \alias{pdim.pggls} 10 | \alias{pdim.pcce} 11 | \alias{pdim.pmg} 12 | \alias{pdim.pgmm} 13 | \alias{pdim.panelmodel} 14 | \alias{print.pdim} 15 | \title{Check for the Dimensions of the Panel} 16 | \usage{ 17 | pdim(x, ...) 18 | 19 | \method{pdim}{default}(x, y, ...) 20 | 21 | \method{pdim}{data.frame}(x, index = NULL, ...) 22 | 23 | \method{pdim}{pdata.frame}(x, ...) 24 | 25 | \method{pdim}{pseries}(x, ...) 26 | 27 | \method{pdim}{pggls}(x, ...) 28 | 29 | \method{pdim}{pcce}(x, ...) 30 | 31 | \method{pdim}{pmg}(x, ...) 32 | 33 | \method{pdim}{pgmm}(x, ...) 34 | 35 | \method{pdim}{panelmodel}(x, ...) 36 | 37 | \method{print}{pdim}(x, ...) 38 | } 39 | \arguments{ 40 | \item{x}{a \code{data.frame}, a \code{pdata.frame}, a \code{pseries}, a 41 | \code{panelmodel}, or a \code{pgmm} object,} 42 | 43 | \item{\dots}{further arguments.} 44 | 45 | \item{y}{a vector,} 46 | 47 | \item{index}{see \code{\link[=pdata.frame]{pdata.frame()}},} 48 | } 49 | \value{ 50 | An object of class \code{pdim} containing the following 51 | elements: 52 | 53 | \item{nT}{a list containing \code{n}, the number of individuals, \code{T}, 54 | the number of time observations, \code{N} the total number of 55 | observations,} 56 | 57 | \item{Tint}{a list containing two vectors (of type integer): \code{Ti} 58 | gives the number of observations for each individual and \code{nt} gives 59 | the number of individuals observed for each period,} 60 | 61 | \item{balanced}{a logical value: \code{TRUE} for a balanced panel, 62 | \code{FALSE} for an unbalanced panel,} 63 | 64 | \item{panel.names}{a list of character vectors: \code{id.names} contains 65 | the names of each individual and \code{time.names} contains the names of 66 | each period.} 67 | } 68 | \description{ 69 | This function checks the number of individuals and time observations in the 70 | panel and whether it is balanced or not. 71 | } 72 | \details{ 73 | \code{pdim} is called by the estimation functions and can be also used 74 | stand-alone. 75 | } 76 | \note{ 77 | Calling \code{pdim} on an estimated \code{panelmodel} object 78 | and on the corresponding \verb{(p)data.frame} used for this 79 | estimation does not necessarily yield the same result. When 80 | called on an estimated \code{panelmodel}, the number of 81 | observations (individual, time) actually used for model 82 | estimation are taken into account. When called on a 83 | \verb{(p)data.frame}, the rows in the \verb{(p)data.frame} are 84 | considered, disregarding any \code{NA} values in the dependent or 85 | independent variable(s) which would be dropped during model 86 | estimation. 87 | } 88 | \examples{ 89 | 90 | # There are 595 individuals 91 | data("Wages", package = "plm") 92 | pdim(Wages, 595) 93 | 94 | # Gasoline contains two variables which are individual and time 95 | # indexes and are the first two variables 96 | data("Gasoline", package="plm") 97 | pdim(Gasoline) 98 | 99 | # Hedonic is an unbalanced panel, townid is the individual index 100 | data("Hedonic", package = "plm") 101 | pdim(Hedonic, "townid") 102 | 103 | # An example of the panelmodel method 104 | data("Produc", package = "plm") 105 | z <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp,data=Produc, 106 | model="random", subset = gsp > 5000) 107 | pdim(z) 108 | 109 | } 110 | \seealso{ 111 | \code{\link[=is.pbalanced]{is.pbalanced()}} to just determine balancedness 112 | of data (slightly faster than \code{pdim}),\cr 113 | \code{\link[=punbalancedness]{punbalancedness()}} for measures of 114 | unbalancedness,\cr \code{\link[=nobs]{nobs()}}, 115 | \code{\link[=pdata.frame]{pdata.frame()}},\cr \code{\link[=pvar]{pvar()}} to check for 116 | each variable if it varies cross-sectionally and over time. 117 | } 118 | \author{ 119 | Yves Croissant 120 | } 121 | \keyword{attribute} 122 | -------------------------------------------------------------------------------- /man/pdwtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_serial.R 3 | \name{pdwtest} 4 | \alias{pdwtest} 5 | \alias{pdwtest.panelmodel} 6 | \alias{pdwtest.formula} 7 | \title{Durbin--Watson Test for Panel Models} 8 | \usage{ 9 | pdwtest(x, ...) 10 | 11 | \method{pdwtest}{panelmodel}(x, ...) 12 | 13 | \method{pdwtest}{formula}(x, data, ...) 14 | } 15 | \arguments{ 16 | \item{x}{an object of class \code{"panelmodel"} or of class 17 | \code{"formula"},} 18 | 19 | \item{\dots}{further arguments to be passed on to \code{dwtest}, 20 | e.g., \code{alternative}, see \code{\link[lmtest:dwtest]{lmtest::dwtest()}} for 21 | further details.} 22 | 23 | \item{data}{a \code{data.frame},} 24 | } 25 | \value{ 26 | An object of class \code{"htest"}. 27 | } 28 | \description{ 29 | Test of serial correlation for (the idiosyncratic component of) the errors 30 | in panel models. 31 | } 32 | \details{ 33 | This Durbin--Watson test uses the auxiliary model on 34 | (quasi-)demeaned data taken from a model of class \code{plm} which may 35 | be a \code{pooling} (the default), \code{random} or \code{within} model. It 36 | performs a Durbin--Watson test (using \code{dwtest} from package 37 | \CRANpkg{lmtest} on the residuals of the (quasi-)demeaned model, 38 | which should be serially uncorrelated under the null of no serial 39 | correlation in idiosyncratic errors. The function takes the 40 | demeaned data, estimates the model and calls \code{dwtest}. Thus, this 41 | test does not take the panel structure of the residuals into 42 | consideration; it shall not be confused with the generalized 43 | Durbin-Watson test for panels in \code{pbnftest}. 44 | } 45 | \examples{ 46 | 47 | data("Grunfeld", package = "plm") 48 | g <- plm(inv ~ value + capital, data = Grunfeld, model="random") 49 | pdwtest(g) 50 | pdwtest(g, alternative="two.sided") 51 | ## formula interface 52 | pdwtest(inv ~ value + capital, data=Grunfeld, model="random") 53 | 54 | } 55 | \references{ 56 | \insertRef{DURB:WATS:50}{plm} 57 | 58 | \insertRef{DURB:WATS:51}{plm} 59 | 60 | \insertRef{DURB:WATS:71}{plm} 61 | 62 | \insertRef{WOOL:02}{plm} 63 | 64 | \insertRef{WOOL:10}{plm} 65 | } 66 | \seealso{ 67 | \code{\link[lmtest:dwtest]{lmtest::dwtest()}} for the Durbin--Watson test 68 | in \CRANpkg{lmtest}, \code{\link[=pbgtest]{pbgtest()}} for the analogous 69 | Breusch--Godfrey test for panel models, 70 | \code{\link[lmtest:bgtest]{lmtest::bgtest()}} for the Breusch--Godfrey test for 71 | serial correlation in the linear model. \code{\link[=pbltest]{pbltest()}}, 72 | \code{\link[=pbsytest]{pbsytest()}}, \code{\link[=pwartest]{pwartest()}} and 73 | \code{\link[=pwfdtest]{pwfdtest()}} for other serial correlation tests for 74 | panel models. 75 | 76 | For the Durbin-Watson test generalized to panel data models see 77 | \code{\link[=pbnftest]{pbnftest()}}. 78 | } 79 | \author{ 80 | Giovanni Millo 81 | } 82 | \keyword{htest} 83 | -------------------------------------------------------------------------------- /man/pggls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_ggls.R 3 | \name{pggls} 4 | \alias{pggls} 5 | \alias{summary.pggls} 6 | \alias{print.summary.pggls} 7 | \alias{residuals.pggls} 8 | \title{General FGLS Estimators} 9 | \usage{ 10 | pggls( 11 | formula, 12 | data, 13 | subset, 14 | na.action, 15 | effect = c("individual", "time"), 16 | model = c("within", "pooling", "fd"), 17 | index = NULL, 18 | ... 19 | ) 20 | 21 | \method{summary}{pggls}(object, ...) 22 | 23 | \method{print}{summary.pggls}( 24 | x, 25 | digits = max(3, getOption("digits") - 2), 26 | width = getOption("width"), 27 | ... 28 | ) 29 | 30 | \method{residuals}{pggls}(object, ...) 31 | } 32 | \arguments{ 33 | \item{formula}{a symbolic description of the model to be estimated,} 34 | 35 | \item{data}{a \code{data.frame},} 36 | 37 | \item{subset}{see \code{\link[=lm]{lm()}},} 38 | 39 | \item{na.action}{see \code{\link[=lm]{lm()}},} 40 | 41 | \item{effect}{the effects introduced in the model, one of 42 | \code{"individual"} or \code{"time"},} 43 | 44 | \item{model}{one of \code{"within"}, \code{"pooling"}, \code{"fd"},} 45 | 46 | \item{index}{the indexes, see \code{\link[=pdata.frame]{pdata.frame()}},} 47 | 48 | \item{\dots}{further arguments.} 49 | 50 | \item{object, x}{an object of class \code{pggls},} 51 | 52 | \item{digits}{digits,} 53 | 54 | \item{width}{the maximum length of the lines in the print output,} 55 | } 56 | \value{ 57 | An object of class \code{c("pggls","panelmodel")} containing: 58 | \item{coefficients}{the vector of coefficients,} 59 | \item{residuals}{the vector of residuals,} 60 | \item{fitted.values}{the vector of fitted values,} 61 | \item{vcov}{the covariance matrix of the coefficients,} 62 | \item{df.residual}{degrees of freedom of the residuals,} 63 | \item{model}{a data.frame containing the variables used for the 64 | estimation,} 65 | \item{call}{the call,} 66 | \item{sigma}{the estimated intragroup (or cross-sectional, if 67 | \code{effect = "time"}) covariance of errors,} 68 | } 69 | \description{ 70 | General FGLS estimators for panel data (balanced or unbalanced) 71 | } 72 | \details{ 73 | \code{pggls} is a function for the estimation of linear panel models by 74 | general feasible generalized least squares, either with or without 75 | fixed effects. General FGLS is based on a two-step estimation 76 | process: first a model is estimated by OLS (\code{model = "pooling"}), 77 | fixed effects (\code{model = "within"}) or first differences 78 | (\code{model = "fd"}), then its residuals are used to estimate an error 79 | covariance matrix for use in a feasible-GLS analysis. This framework allows 80 | the error covariance structure inside every group 81 | (if \code{effect = "individual"}, else symmetric) of observations to be fully 82 | unrestricted and is therefore robust against any type of intragroup 83 | heteroskedasticity and serial correlation. Conversely, this 84 | structure is assumed identical across groups and thus general FGLS 85 | estimation is inefficient under groupwise heteroskedasticity. Note 86 | also that this method requires estimation of \eqn{T(T+1)/2} 87 | variance parameters, thus efficiency requires N >> T 88 | (if \code{effect = "individual"}, else the opposite). 89 | 90 | If \code{model = "within"} (the default) then a FEGLS (fixed effects GLS, see 91 | Wooldridge, Ch. 10.5) is estimated; if \code{model = "fd"} a FDGLS 92 | (first-difference GLS). Setting \code{model = "pooling"} produces an unrestricted 93 | FGLS model (see ibid.) (\code{model = "random"} does the same, but using this value 94 | is deprecated and included only for retro--compatibility reasons). 95 | } 96 | \examples{ 97 | 98 | data("Produc", package = "plm") 99 | zz_wi <- pggls(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, 100 | data = Produc, model = "within") 101 | summary(zz_wi) 102 | 103 | zz_pool <- pggls(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, 104 | data = Produc, model = "pooling") 105 | summary(zz_pool) 106 | 107 | zz_fd <- pggls(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, 108 | data = Produc, model = "fd") 109 | summary(zz_fd) 110 | 111 | 112 | } 113 | \references{ 114 | \insertRef{IM:SEUN:SCHM:WOOL:99}{plm} 115 | 116 | \insertRef{KIEF:80}{plm} 117 | 118 | \insertRef{WOOL:02}{plm} 119 | 120 | \insertRef{WOOL:10}{plm} 121 | } 122 | \author{ 123 | Giovanni Millo 124 | } 125 | \keyword{regression} 126 | -------------------------------------------------------------------------------- /man/pgrangertest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_granger.R 3 | \name{pgrangertest} 4 | \alias{pgrangertest} 5 | \title{Panel Granger (Non-)Causality Test (Dumitrescu/Hurlin (2012))} 6 | \usage{ 7 | pgrangertest( 8 | formula, 9 | data, 10 | test = c("Ztilde", "Zbar", "Wbar"), 11 | order = 1L, 12 | index = NULL 13 | ) 14 | } 15 | \arguments{ 16 | \item{formula}{a \code{formula} object to describe the direction of the 17 | hypothesized Granger causation,} 18 | 19 | \item{data}{a \code{pdata.frame} or a \code{data.frame},} 20 | 21 | \item{test}{a character to request the statistic to be returned, 22 | either \code{"Ztilde"} (default),or \code{"Zbar"}, alternatively, set to 23 | \code{"Wbar"} for an intermediate statistic (see Details),} 24 | 25 | \item{order}{integer(s) giving the number of lags to include in the 26 | test's auxiliary regressions, the length of order must be 27 | either 1 (same lag order for all individuals) or equal to the 28 | number of individuals (to specify a lag order per individual),} 29 | 30 | \item{index}{only relevant if \code{data} is \code{data.frame} and not a 31 | \code{pdata.frame}; if \code{NULL}, the first two columns of the 32 | data.frame are assumed to be the index variables, for further 33 | details see \code{\link[=pdata.frame]{pdata.frame()}}.} 34 | } 35 | \value{ 36 | An object of class \code{c("pgrangertest", "htest")}. Besides 37 | the usual elements of a \code{htest} object, it contains the data 38 | frame \code{indgranger} which carries the Granger test statistics 39 | per individual along the associated p-values, degrees of 40 | freedom, and the specified lag order. 41 | } 42 | \description{ 43 | Test for Granger (non-)causality in panel data. 44 | } 45 | \details{ 46 | The panel Granger (non-)causality test is a combination of Granger 47 | tests \insertCite{GRAN:69}{plm} performed per individual. The test 48 | is developed by \insertCite{DUMI:HURL:12;textual}{plm}, a shorter 49 | exposition is given in \insertCite{LOPE:WEBE:17;textual}{plm}. 50 | 51 | The formula \code{formula} describes the direction of the (panel) Granger 52 | causation where \code{y ~ x} means "x (panel) Granger causes y". 53 | 54 | By setting argument \code{test} to either \code{"Ztilde"} (default) or 55 | \code{"Zbar"}, two different statistics can be requested. \code{"Ztilde"} 56 | gives the standardised statistic recommended by Dumitrescu/Hurlin (2012) for 57 | fixed T samples. If set to \code{"Wbar"}, the intermediate Wbar statistic 58 | (average of individual Granger chi-square statistics) is given which is used 59 | to derive the other two. 60 | 61 | The Zbar statistic is not suitable for unbalanced panels. For the Wbar 62 | statistic, no p-value is available. 63 | 64 | The implementation uses \code{\link[lmtest:grangertest]{lmtest::grangertest()}} from 65 | package \CRANpkg{lmtest} to perform the individual Granger tests. 66 | } 67 | \examples{ 68 | 69 | ## not meaningful, just to demonstrate usage 70 | ## H0: 'value' does not Granger cause 'inv' for all invididuals 71 | 72 | data("Grunfeld", package = "plm") 73 | pgrangertest(inv ~ value, data = Grunfeld) 74 | pgrangertest(inv ~ value, data = Grunfeld, order = 2L) 75 | pgrangertest(inv ~ value, data = Grunfeld, order = 2L, test = "Zbar") 76 | 77 | # varying lag order (last individual lag order 3, others lag order 2) 78 | (pgrt <- pgrangertest(inv ~ value, data = Grunfeld, order = c(rep(2L, 9), 3L))) 79 | # chisq statistics per individual 80 | pgrt$indgranger 81 | 82 | } 83 | \references{ 84 | \insertRef{DUMI:HURL:12}{plm} 85 | 86 | \insertRef{GRAN:69}{plm} 87 | 88 | \insertRef{LOPE:WEBE:17}{plm} 89 | } 90 | \seealso{ 91 | \code{\link[lmtest:grangertest]{lmtest::grangertest()}} for the original (non-panel) 92 | Granger causality test in \CRANpkg{lmtest}. 93 | } 94 | \author{ 95 | Kevin Tappe 96 | } 97 | \keyword{htest} 98 | -------------------------------------------------------------------------------- /man/phansitest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_uroot.R 3 | \name{phansitest} 4 | \alias{phansitest} 5 | \alias{print.phansitest} 6 | \title{Simes Test for unit roots in panel data} 7 | \usage{ 8 | phansitest(object, alpha = 0.05) 9 | 10 | \method{print}{phansitest}(x, cutoff = 10L, ...) 11 | } 12 | \arguments{ 13 | \item{object}{either a numeric containing p-values of individual unit root 14 | test results (does not need to be sorted) or a suitable \code{purtest} object 15 | (as produced by \code{purtest()} for a test which gives p-values of the individuals 16 | (Hadri's test in \code{purtest} is not suitable)),} 17 | 18 | \item{alpha}{numeric, the pre-specified significance level (defaults to \code{0.05}),} 19 | 20 | \item{x}{an object of class \code{c("phansitest", "list")} as produced by 21 | \code{phansitest} to be printed,} 22 | 23 | \item{cutoff}{integer, cutoff value for printing of enumeration of individuals 24 | with rejected individual H0, for print method only,} 25 | 26 | \item{\dots}{further arguments (currently not used).} 27 | } 28 | \value{ 29 | For \code{phansitest}, an object of class \code{c("phansitest", "list")} which 30 | is a list with the elements: 31 | \itemize{ 32 | \item \code{id}: integer, the identifier of the individual (integer sequence referring to 33 | position in input), 34 | \item \code{name}: character, name of the input's individual (if it has a name, 35 | otherwise "1", "2", "3", ...), 36 | \item \code{p}: numeric, p-values as input (either the numeric or extracted from 37 | the purtest object), 38 | \item \code{p.hommel}: numeric, p-values after Hommel's transformation, 39 | \item \code{rejected}: logical, indicating for which individual the individual null 40 | hypothesis is rejected (\code{TRUE})/non-rejected (\code{FALSE}) (after controlling 41 | for multiplicity), 42 | \item \code{rejected.no}: integer, giving the total number of rejected individual series, 43 | \item \code{alpha}: numeric, the input \code{alpha}. 44 | } 45 | } 46 | \description{ 47 | Simes' test of intersection of individual hypothesis tests 48 | (\insertCite{SIMES:86;textual}{plm}) applied to panel unit root tests as 49 | suggested by \insertCite{HANCK:13;textual}{plm}. 50 | } 51 | \details{ 52 | Simes' approach to testing is combining p-values from single hypothesis tests 53 | with a global (intersected) hypothesis. \insertCite{HANCK:13;textual}{plm} 54 | mentions it can be applied to any panel unit root test which yields a p-value 55 | for each individual series. 56 | The test is robust versus general patterns of cross-sectional dependence. 57 | 58 | Further, this approach allows to discriminate between individuals for which 59 | the individual H0 (unit root present for individual series) is rejected/is 60 | not rejected by Hommel's procedure (\insertCite{HOMM:88;textual}{plm}) for 61 | family-wise error rate control (FWER) at a pre-specified significance level 62 | \eqn{\alpha} via argument \code{alpha} (defaulting to \code{0.05}), i.e., it controls 63 | for the multiplicity in testing. 64 | 65 | The function \code{phansitest} takes as main input \code{object} either a plain numeric 66 | containing p-values of individual tests or a \code{purtest} object which holds 67 | a suitable pre-computed panel unit root test (one that produces p-values per 68 | individual series). 69 | 70 | The function's return value (see section Value) is a list with detailed 71 | evaluation of the applied Simes test. 72 | 73 | The associated \code{print} method prints a verbal evaluation. 74 | } 75 | \examples{ 76 | 77 | ### input is numeric (p-values) 78 | #### example from Hanck (2013), Table 11 (left side) 79 | pvals <- c(0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0050,0.0050,0.0050, 80 | 0.0050,0.0175,0.0175,0.0200,0.0250,0.0400,0.0500,0.0575,0.2375,0.2475) 81 | 82 | countries <- c("Argentina","Sweden","Norway","Mexico","Italy","Finland","France", 83 | "Germany","Belgium","U.K.","Brazil","Australia","Netherlands", 84 | "Portugal","Canada", "Spain","Denmark","Switzerland","Japan") 85 | names(pvals) <- countries 86 | 87 | h <- phansitest(pvals) 88 | print(h) # (explicitly) prints test's evaluation 89 | print(h, cutoff = 3L) # print only first 3 rejected ids 90 | h$rejected # logical indicating the individuals with rejected individual H0 91 | 92 | 93 | ### input is a (suitable) purtest object 94 | data("Grunfeld", package = "plm") 95 | y <- data.frame(split(Grunfeld$inv, Grunfeld$firm)) 96 | obj <- purtest(y, pmax = 4, exo = "intercept", test = "madwu") 97 | 98 | phansitest(obj) 99 | 100 | } 101 | \references{ 102 | \insertAllCited{} 103 | } 104 | \seealso{ 105 | \code{\link[=purtest]{purtest()}}, \code{\link[=cipstest]{cipstest()}} 106 | } 107 | \author{ 108 | Kevin Tappe 109 | } 110 | \keyword{htest} 111 | -------------------------------------------------------------------------------- /man/pht.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated.R 3 | \name{pht} 4 | \alias{pht} 5 | \alias{summary.pht} 6 | \alias{print.summary.pht} 7 | \title{Hausman--Taylor Estimator for Panel Data} 8 | \usage{ 9 | pht( 10 | formula, 11 | data, 12 | subset, 13 | na.action, 14 | model = c("ht", "am", "bms"), 15 | index = NULL, 16 | ... 17 | ) 18 | 19 | \method{summary}{pht}(object, ...) 20 | 21 | \method{print}{summary.pht}( 22 | x, 23 | digits = max(3, getOption("digits") - 2), 24 | width = getOption("width"), 25 | subset = NULL, 26 | ... 27 | ) 28 | } 29 | \arguments{ 30 | \item{formula}{a symbolic description for the model to be 31 | estimated,} 32 | 33 | \item{data}{a \code{data.frame},} 34 | 35 | \item{subset}{see \code{\link[=lm]{lm()}} for \code{"plm"}, a character or 36 | numeric vector indicating a subset of the table of coefficient 37 | to be printed for \code{"print.summary.plm"},} 38 | 39 | \item{na.action}{see \code{\link[=lm]{lm()}},} 40 | 41 | \item{model}{one of \code{"ht"} for Hausman--Taylor, \code{"am"} 42 | for Amemiya--MaCurdy and \code{"bms"} for 43 | Breusch--Mizon--Schmidt,} 44 | 45 | \item{index}{the indexes,} 46 | 47 | \item{\dots}{further arguments.} 48 | 49 | \item{object, x}{an object of class \code{"plm"},} 50 | 51 | \item{digits}{digits,} 52 | 53 | \item{width}{the maximum length of the lines in the print output,} 54 | } 55 | \value{ 56 | An object of class \code{c("pht", "plm", "panelmodel")}. 57 | 58 | A \code{"pht"} object contains the same elements as \code{plm} 59 | object, with a further argument called \code{varlist} which 60 | describes the typology of the variables. It has \code{summary} and 61 | \code{print.summary} methods. 62 | } 63 | \description{ 64 | The Hausman--Taylor estimator is an instrumental variable estimator without 65 | external instruments (function deprecated). 66 | } 67 | \details{ 68 | \code{pht} estimates panels models using the Hausman--Taylor estimator, 69 | Amemiya--MaCurdy estimator, or Breusch--Mizon--Schmidt estimator, depending 70 | on the argument \code{model}. The model is specified as a two--part formula, 71 | the second part containing the exogenous variables. 72 | } 73 | \note{ 74 | The function \code{pht} is deprecated. Please use function \code{plm} 75 | to estimate Taylor--Hausman models like this with a three-part 76 | formula as shown in the example:\cr \verb{plm(, random.method = "ht", model = "random", inst.method = "baltagi")}. The Amemiya--MaCurdy estimator and the 77 | Breusch--Mizon--Schmidt estimator is computed likewise with 78 | \code{plm}. 79 | } 80 | \examples{ 81 | 82 | ## replicates Baltagi (2005, 2013), table 7.4; Baltagi (2021), table 7.5 83 | ## preferred way with plm() 84 | data("Wages", package = "plm") 85 | ht <- plm(lwage ~ wks + south + smsa + married + exp + I(exp ^ 2) + 86 | bluecol + ind + union + sex + black + ed | 87 | bluecol + south + smsa + ind + sex + black | 88 | wks + married + union + exp + I(exp ^ 2), 89 | data = Wages, index = 595, 90 | random.method = "ht", model = "random", inst.method = "baltagi") 91 | summary(ht) 92 | 93 | am <- plm(lwage ~ wks + south + smsa + married + exp + I(exp ^ 2) + 94 | bluecol + ind + union + sex + black + ed | 95 | bluecol + south + smsa + ind + sex + black | 96 | wks + married + union + exp + I(exp ^ 2), 97 | data = Wages, index = 595, 98 | random.method = "ht", model = "random", inst.method = "am") 99 | summary(am) 100 | 101 | ## deprecated way with pht() for HT 102 | #ht <- pht(lwage ~ wks + south + smsa + married + exp + I(exp^2) + 103 | # bluecol + ind + union + sex + black + ed | 104 | # sex + black + bluecol + south + smsa + ind, 105 | # data = Wages, model = "ht", index = 595) 106 | #summary(ht) 107 | # deprecated way with pht() for AM 108 | #am <- pht(lwage ~ wks + south + smsa + married + exp + I(exp^2) + 109 | # bluecol + ind + union + sex + black + ed | 110 | # sex + black + bluecol + south + smsa + ind, 111 | # data = Wages, model = "am", index = 595) 112 | #summary(am) 113 | 114 | 115 | } 116 | \references{ 117 | \insertCite{AMEM:MACU:86}{plm} 118 | 119 | \insertCite{BALT:13}{plm} 120 | 121 | \insertCite{BREU:MIZO:SCHM:89}{plm} 122 | 123 | \insertCite{HAUS:TAYL:81}{plm} 124 | } 125 | \author{ 126 | Yves Croissant 127 | } 128 | \keyword{regression} 129 | -------------------------------------------------------------------------------- /man/phtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_general.R 3 | \name{phtest} 4 | \alias{phtest} 5 | \alias{phtest.formula} 6 | \alias{phtest.panelmodel} 7 | \title{Hausman Test for Panel Models} 8 | \usage{ 9 | phtest(x, ...) 10 | 11 | \method{phtest}{formula}( 12 | x, 13 | data, 14 | model = c("within", "random"), 15 | effect = c("individual", "time", "twoways"), 16 | method = c("chisq", "aux"), 17 | index = NULL, 18 | vcov = NULL, 19 | ... 20 | ) 21 | 22 | \method{phtest}{panelmodel}(x, x2, ...) 23 | } 24 | \arguments{ 25 | \item{x}{an object of class \code{"panelmodel"} or \code{"formula"},} 26 | 27 | \item{\dots}{further arguments to be passed on (currently none).} 28 | 29 | \item{data}{a \code{data.frame},} 30 | 31 | \item{model}{a character vector containing the names of two models 32 | (length(model) must be 2),} 33 | 34 | \item{effect}{a character specifying the effect to be introduced to both models, 35 | one of \code{"individual"}, \code{"time"}, or \code{"twoways"} (only for formula method),} 36 | 37 | \item{method}{one of \code{"chisq"} or \code{"aux"},} 38 | 39 | \item{index}{an optional vector of index variables,} 40 | 41 | \item{vcov}{an optional covariance function,} 42 | 43 | \item{x2}{an object of class \code{"panelmodel"} (only for panelmodel method/interface),} 44 | } 45 | \value{ 46 | An object of class \code{"htest"}. 47 | } 48 | \description{ 49 | Specification test for panel models. 50 | } 51 | \details{ 52 | The Hausman test (sometimes also called Durbin--Wu--Hausman test) 53 | is based on the difference of the vectors of coefficients of two 54 | different models. The \code{panelmodel} method computes the original 55 | version of the test based on a quadratic form 56 | \insertCite{HAUS:78}{plm}. The \code{formula} method, if 57 | \code{method = "chisq"} (default), computes the original version of the 58 | test based on a quadratic form; if \code{method ="aux"} then the 59 | auxiliary-regression-based version as in \insertCite{WOOL:10;textual}{plm}, 60 | Sec.10.7.3. Only the latter can be robustified by specifying a robust 61 | covariance estimator as a function through the argument \code{vcov} (see 62 | \strong{Examples}). 63 | 64 | The \code{effect} argument is only relevant for the formula method/interface and 65 | is then applied to both models. For the panelmodel method/interface, the test 66 | is run with the effects of the already estimated models. 67 | 68 | The equivalent tests in the \strong{one-way} case using a between 69 | model (either "within vs. between" or "random vs. between") 70 | \insertCite{@see @HAUS:TAYL:81 or @BALT:13 Sec.4.3}{plm} can also 71 | be performed by \code{phtest}, but only for \code{test = "chisq"}, not for 72 | the regression-based test. NB: These equivalent tests using the 73 | between model do not extend to the two-ways case. There are, 74 | however, some other equivalent tests, 75 | \insertCite{@see @KANG:85 or @BALT:13 Sec.4.3.7}{plm}, 76 | but those are unsupported by \code{phtest}. 77 | } 78 | \examples{ 79 | 80 | data("Gasoline", package = "plm") 81 | form <- lgaspcar ~ lincomep + lrpmg + lcarpcap 82 | wi <- plm(form, data = Gasoline, model = "within") 83 | re <- plm(form, data = Gasoline, model = "random") 84 | phtest(wi, re) 85 | phtest(form, data = Gasoline) 86 | phtest(form, data = Gasoline, effect = "time") 87 | 88 | # Regression-based Hausman test 89 | phtest(form, data = Gasoline, method = "aux") 90 | 91 | # robust Hausman test with vcov supplied as a function and 92 | # with additional parameters 93 | phtest(form, data = Gasoline, method = "aux", vcov = vcovHC) 94 | phtest(form, data = Gasoline, method = "aux", 95 | vcov = function(x) vcovHC(x, method="white2", type="HC3")) 96 | 97 | } 98 | \references{ 99 | \insertRef{HAUS:78}{plm} 100 | 101 | \insertRef{HAUS:TAYL:81}{plm} 102 | 103 | \insertRef{KANG:85}{plm} 104 | 105 | \insertRef{WOOL:10}{plm} 106 | 107 | \insertRef{BALT:13}{plm} 108 | } 109 | \author{ 110 | Yves Croissant, Giovanni Millo 111 | } 112 | \keyword{htest} 113 | -------------------------------------------------------------------------------- /man/piest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_pi.R 3 | \name{piest} 4 | \alias{piest} 5 | \alias{print.piest} 6 | \alias{summary.piest} 7 | \alias{print.summary.piest} 8 | \title{Chamberlain estimator and test for fixed effects} 9 | \usage{ 10 | piest(formula, data, subset, na.action, index = NULL, robust = TRUE, ...) 11 | 12 | \method{print}{piest}(x, ...) 13 | 14 | \method{summary}{piest}(object, ...) 15 | 16 | \method{print}{summary.piest}( 17 | x, 18 | digits = max(3, getOption("digits") - 2), 19 | width = getOption("width"), 20 | subset = NULL, 21 | ... 22 | ) 23 | } 24 | \arguments{ 25 | \item{formula}{a symbolic description for the model to be estimated,} 26 | 27 | \item{data}{a \code{data.frame},} 28 | 29 | \item{subset}{see \code{\link[=lm]{lm()}},} 30 | 31 | \item{na.action}{see \code{\link[=lm]{lm()}},} 32 | 33 | \item{index}{the indexes,} 34 | 35 | \item{robust}{logical, if \code{FALSE}, the error is assumed to be spherical, 36 | if \code{TRUE}, a robust estimation of the covariance matrix is computed,} 37 | 38 | \item{\dots}{further arguments.} 39 | 40 | \item{object, x}{an object of class \code{"piest"} and of class \code{"summary.piest"} 41 | for the print method of summary for piest objects,} 42 | 43 | \item{digits}{number of digits for printed output,} 44 | 45 | \item{width}{the maximum length of the lines in the printed output,} 46 | } 47 | \value{ 48 | An object of class \code{"piest"}. 49 | } 50 | \description{ 51 | General estimator useful for testing the within specification 52 | } 53 | \details{ 54 | The Chamberlain method consists in using the covariates of all the 55 | periods as regressors. It allows to test the within specification. 56 | } 57 | \examples{ 58 | 59 | data("RiceFarms", package = "plm") 60 | pirice <- piest(log(goutput) ~ log(seed) + log(totlabor) + log(size), RiceFarms, index = "id") 61 | summary(pirice) 62 | 63 | } 64 | \references{ 65 | \insertRef{CHAM:82}{plm} 66 | } 67 | \seealso{ 68 | \code{\link[=aneweytest]{aneweytest()}} 69 | } 70 | \author{ 71 | Yves Croissant 72 | } 73 | \keyword{htest} 74 | -------------------------------------------------------------------------------- /man/pldv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_ldv.R 3 | \name{pldv} 4 | \alias{pldv} 5 | \title{Panel estimators for limited dependent variables} 6 | \usage{ 7 | pldv( 8 | formula, 9 | data, 10 | subset, 11 | weights, 12 | na.action, 13 | model = c("fd", "random", "pooling"), 14 | index = NULL, 15 | R = 20, 16 | start = NULL, 17 | lower = 0, 18 | upper = +Inf, 19 | objfun = c("lsq", "lad"), 20 | sample = c("cens", "trunc"), 21 | ... 22 | ) 23 | } 24 | \arguments{ 25 | \item{formula}{a symbolic description for the model to be 26 | estimated,} 27 | 28 | \item{data}{a \code{data.frame},} 29 | 30 | \item{subset}{see \code{lm},} 31 | 32 | \item{weights}{see \code{lm},} 33 | 34 | \item{na.action}{see \code{lm},} 35 | 36 | \item{model}{one of \code{"fd"}, \code{"random"}, or \code{"pooling"},} 37 | 38 | \item{index}{the indexes, see \code{\link[=pdata.frame]{pdata.frame()}},} 39 | 40 | \item{R}{the number of points for the gaussian quadrature,} 41 | 42 | \item{start}{a vector of starting values,} 43 | 44 | \item{lower}{the lower bound for the censored/truncated dependent 45 | variable,} 46 | 47 | \item{upper}{the upper bound for the censored/truncated dependent 48 | variable,} 49 | 50 | \item{objfun}{the objective function for the fixed effect model (\code{model = "fd"}, 51 | irrelevant for other values of the \code{model} argument ): 52 | one of \code{"lsq"} for least squares (minimise sum of squares of the residuals) 53 | and \code{"lad"} for least absolute deviations (minimise sum of absolute values 54 | of the residuals),} 55 | 56 | \item{sample}{\code{"cens"} for a censored (tobit-like) sample, 57 | \code{"trunc"} for a truncated sample,} 58 | 59 | \item{\dots}{further arguments.} 60 | } 61 | \value{ 62 | For \code{model = "fd"}, an object of class \code{c("plm", "panelmodel")}, for 63 | \code{model = "random"} and \code{model = "pooling"} an object of class \code{c("maxLik", "maxim")}. 64 | } 65 | \description{ 66 | Fixed and random effects estimators for truncated or censored 67 | limited dependent variable 68 | } 69 | \details{ 70 | \code{pldv} computes two kinds of models: a LSQ/LAD estimator for the 71 | first-difference model (\code{model = "fd"}) and a maximum likelihood estimator 72 | with an assumed normal distribution for the individual effects 73 | (\code{model = "random"} or \code{"pooling"}). 74 | 75 | For maximum-likelihood estimations, \code{pldv} uses internally function 76 | \code{\link[maxLik:maxLik]{maxLik::maxLik()}} (from package \CRANpkg{maxLik}). 77 | } 78 | \examples{ 79 | ## as these examples take a bit of time, do not run them automatically 80 | \dontrun{ 81 | data("Donors", package = "pder") 82 | library("plm") 83 | pDonors <- pdata.frame(Donors, index = "id") 84 | 85 | # replicate Landry/Lange/List/Price/Rupp (2010), online appendix, table 5a, models A and B 86 | modA <- pldv(donation ~ treatment + prcontr, data = pDonors, 87 | model = "random", method = "bfgs") 88 | summary(modA) 89 | modB <- pldv(donation ~ treatment * prcontr - prcontr, data = pDonors, 90 | model = "random", method = "bfgs") 91 | summary(modB) 92 | } 93 | 94 | } 95 | \references{ 96 | \insertRef{HONO:92}{plm} 97 | } 98 | \author{ 99 | Yves Croissant 100 | } 101 | \keyword{regression} 102 | -------------------------------------------------------------------------------- /man/plm-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated.R 3 | \name{plm-deprecated} 4 | \alias{plm-deprecated} 5 | \alias{detect_lin_dep} 6 | \alias{pvcovHC} 7 | \alias{plm.data} 8 | \alias{dynformula} 9 | \alias{formula.dynformula} 10 | \alias{print.dynformula} 11 | \title{Deprecated functions of plm} 12 | \usage{ 13 | pvcovHC(x, ...) 14 | 15 | plm.data(x, indexes = NULL) 16 | 17 | dynformula(formula, lag.form = NULL, diff.form = NULL, log.form = NULL) 18 | 19 | \method{formula}{dynformula}(x, ...) 20 | 21 | \method{print}{dynformula}(x, ...) 22 | } 23 | \arguments{ 24 | \item{x}{an object of class \code{"plm"},} 25 | 26 | \item{\dots}{further arguments.} 27 | 28 | \item{indexes}{a vector (of length one or two) indicating the (individual 29 | and time) indexes (see Details);} 30 | 31 | \item{formula}{a formula,} 32 | 33 | \item{lag.form}{a list containing the lag structure of each variable in the 34 | formula,} 35 | 36 | \item{diff.form}{a vector (or a list) of logical values indicating whether 37 | variables should be differenced,} 38 | 39 | \item{log.form}{a vector (or a list) of logical values indicating whether 40 | variables should be in logarithms.} 41 | 42 | \item{data}{a \code{data.frame},} 43 | } 44 | \description{ 45 | \code{dynformula}, \code{pht}, \code{plm.data}, and \code{pvcovHC} are 46 | deprecated functions which could be removed from \pkg{plm} in a near future. 47 | } 48 | \details{ 49 | \code{dynformula} was used to construct a dynamic formula which was the 50 | first argument of \code{pgmm}. \code{pgmm} uses now multi-part formulas. 51 | 52 | \code{pht} estimates the Hausman-Taylor model, which can now be estimated 53 | using the more general \code{plm} function. 54 | 55 | \code{plm.data} is replaced by \code{pdata.frame}. 56 | 57 | \code{pvcovHC} is replaced by \code{vcovHC}. 58 | 59 | \code{detect_lin_dep} was renamed to \code{detect.lindep}. 60 | } 61 | -------------------------------------------------------------------------------- /man/plm-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \docType{package} 4 | \name{plm-package} 5 | \alias{plm-package} 6 | \title{plm package: linear models for panel data} 7 | \description{ 8 | plm is a package for R which intends to make the estimation of linear panel 9 | models straightforward. plm provides functions to estimate a wide variety of 10 | models and to make (robust) inference. 11 | } 12 | \details{ 13 | For a gentle and comprehensive introduction to the package, please see the 14 | package's vignette. 15 | 16 | The main functions to estimate models are: 17 | \itemize{ 18 | \item \code{plm}: panel data estimators using \code{lm} on transformed data, 19 | \item \code{pvcm}: variable coefficients models 20 | \item \code{pgmm}: generalized method of moments (GMM) estimation for panel 21 | data, 22 | \item \code{pggls}: estimation of general feasible generalized least squares models, 23 | \item \code{pmg}: mean groups (MG), demeaned MG and common correlated effects 24 | (CCEMG) estimators, 25 | \item \code{pcce}: estimators for common correlated effects mean groups (CCEMG) and 26 | pooled (CCEP) for panel data with common factors, 27 | \item \code{pldv}: panel estimators for limited dependent variables. 28 | } 29 | 30 | Next to the model estimation functions, the package offers several 31 | functions for statistical tests related to panel data/models. 32 | 33 | Multiple functions for (robust) variance--covariance matrices are 34 | at hand as well. 35 | 36 | The package also provides data sets to demonstrate functions and to 37 | replicate some text book/paper results. Use 38 | \code{data(package="plm")} to view a list of available data sets in 39 | the package. 40 | } 41 | \examples{ 42 | 43 | data("Produc", package = "plm") 44 | zz <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, 45 | data = Produc, index = c("state","year")) 46 | summary(zz) 47 | 48 | # replicates some results from Baltagi (2013), table 3.1 49 | data("Grunfeld", package = "plm") 50 | p <- plm(inv ~ value + capital, 51 | data = Grunfeld, model="pooling") 52 | 53 | wi <- plm(inv ~ value + capital, 54 | data = Grunfeld, model="within", effect = "twoways") 55 | 56 | swar <- plm(inv ~ value + capital, 57 | data = Grunfeld, model="random", effect = "twoways") 58 | 59 | amemiya <- plm(inv ~ value + capital, 60 | data = Grunfeld, model = "random", random.method = "amemiya", 61 | effect = "twoways") 62 | 63 | walhus <- plm(inv ~ value + capital, 64 | data = Grunfeld, model = "random", random.method = "walhus", 65 | effect = "twoways") 66 | 67 | } 68 | \seealso{ 69 | Useful links: 70 | \itemize{ 71 | \item \url{https://cran.r-project.org/package=plm} 72 | \item \url{https://github.com/ycroissant/plm} 73 | \item Report bugs at \url{https://github.com/ycroissant/plm/issues} 74 | } 75 | 76 | } 77 | \author{ 78 | \strong{Maintainer}: Kevin Tappe \email{kevin.tappe@bwi.uni-stuttgart.de} 79 | 80 | Authors: 81 | \itemize{ 82 | \item Yves Croissant \email{yves.croissant@univ-reunion.fr} 83 | \item Giovanni Millo \email{giovanni.millo@deams.units.it} 84 | } 85 | 86 | Other contributors: 87 | \itemize{ 88 | \item Ott Toomet \email{otoomet@gmail.com} [contributor] 89 | \item Christian Kleiber \email{Christian.Kleiber@unibas.ch} [contributor] 90 | \item Achim Zeileis \email{Achim.Zeileis@R-project.org} [contributor] 91 | \item Arne Henningsen \email{arne.henningsen@googlemail.com} [contributor] 92 | \item Liviu Andronic [contributor] 93 | \item Nina Schoenfelder [contributor] 94 | } 95 | 96 | } 97 | \keyword{package} 98 | -------------------------------------------------------------------------------- /man/plmtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_general.R 3 | \name{plmtest} 4 | \alias{plmtest} 5 | \alias{plmtest.plm} 6 | \alias{plmtest.formula} 7 | \title{Lagrange FF Multiplier Tests for Panel Models} 8 | \usage{ 9 | plmtest(x, ...) 10 | 11 | \method{plmtest}{plm}( 12 | x, 13 | effect = c("individual", "time", "twoways"), 14 | type = c("honda", "bp", "ghm", "kw"), 15 | ... 16 | ) 17 | 18 | \method{plmtest}{formula}( 19 | x, 20 | data, 21 | ..., 22 | effect = c("individual", "time", "twoways"), 23 | type = c("honda", "bp", "ghm", "kw") 24 | ) 25 | } 26 | \arguments{ 27 | \item{x}{an object of class \code{"plm"} or a formula of class 28 | \code{"formula"},} 29 | 30 | \item{\dots}{further arguments passed to \code{plmtest}.} 31 | 32 | \item{effect}{a character string indicating which effects are 33 | tested: individual effects (\code{"individual"}), time effects 34 | (\code{"time"}) or both (\code{"twoways"}),} 35 | 36 | \item{type}{a character string indicating the test to be performed: 37 | \itemize{ 38 | \item \code{"honda"} (default) for \insertCite{HOND:85;textual}{plm}, 39 | \item \code{"bp"} for \insertCite{BREU:PAGA:80;textual}{plm}, 40 | \item \code{"kw"} for \insertCite{KING:WU:97;textual}{plm}, or 41 | \item \code{"ghm"} for \insertCite{GOUR:HOLL:MONF:82;textual}{plm} for 42 | unbalanced panel data sets, the respective unbalanced version 43 | of the tests are computed, 44 | }} 45 | 46 | \item{data}{a \code{data.frame},} 47 | } 48 | \value{ 49 | An object of class \code{"htest"}. 50 | } 51 | \description{ 52 | Test of individual and/or time effects for panel models. 53 | } 54 | \details{ 55 | These Lagrange multiplier tests use only the residuals of the 56 | pooling model. The first argument of this function may be either a 57 | pooling model of class \code{plm} or an object of class \code{formula} 58 | describing the model. For input within (fixed effects) or random 59 | effects models, the corresponding pooling model is calculated 60 | internally first as the tests are based on the residuals of the 61 | pooling model. 62 | 63 | The \code{"bp"} test for unbalanced panels was derived in 64 | \insertCite{BALT:LI:90;textual}{plm} 65 | (1990), the \code{"kw"} test for unbalanced panels in 66 | \insertCite{BALT:CHAN:LI:98;textual}{plm}. 67 | 68 | The \code{"ghm"} test and the \code{"kw"} test were extended to two-way 69 | effects in \insertCite{BALT:CHAN:LI:92;textual}{plm}. 70 | 71 | For a concise overview of all these statistics see 72 | \insertCite{BALT:03;textual}{plm}, Sec. 4.2, pp. 68--76 (for balanced 73 | panels) and Sec. 9.5, pp. 200--203 (for unbalanced panels). 74 | } 75 | \note{ 76 | For the King-Wu statistics (\code{"kw"}), the oneway statistics 77 | (\code{"individual"} and \code{"time"}) coincide with the respective 78 | Honda statistics (\code{"honda"}); twoway statistics of \code{"kw"} and 79 | \code{"honda"} differ. 80 | } 81 | \examples{ 82 | 83 | data("Grunfeld", package = "plm") 84 | g <- plm(inv ~ value + capital, data = Grunfeld, model = "pooling") 85 | plmtest(g) 86 | plmtest(g, effect="time") 87 | plmtest(inv ~ value + capital, data = Grunfeld, type = "honda") 88 | plmtest(inv ~ value + capital, data = Grunfeld, type = "bp") 89 | plmtest(inv ~ value + capital, data = Grunfeld, type = "bp", effect = "twoways") 90 | plmtest(inv ~ value + capital, data = Grunfeld, type = "ghm", effect = "twoways") 91 | plmtest(inv ~ value + capital, data = Grunfeld, type = "kw", effect = "twoways") 92 | 93 | Grunfeld_unbal <- Grunfeld[1:(nrow(Grunfeld)-1), ] # create an unbalanced panel data set 94 | g_unbal <- plm(inv ~ value + capital, data = Grunfeld_unbal, model = "pooling") 95 | plmtest(g_unbal) # unbalanced version of test is indicated in output 96 | 97 | } 98 | \references{ 99 | \insertRef{BALT:13}{plm} 100 | 101 | \insertRef{BALT:LI:90}{plm} 102 | 103 | \insertRef{BALT:CHAN:LI:92}{plm} 104 | 105 | \insertRef{BALT:CHAN:LI:98}{plm} 106 | 107 | \insertRef{BREU:PAGA:80}{plm} 108 | 109 | \insertRef{GOUR:HOLL:MONF:82}{plm} 110 | 111 | \insertRef{HOND:85}{plm} 112 | 113 | \insertRef{KING:WU:97}{plm} 114 | } 115 | \seealso{ 116 | \code{\link[=pFtest]{pFtest()}} for individual and/or time effects tests based 117 | on the within model. 118 | } 119 | \author{ 120 | Yves Croissant (initial implementation), Kevin Tappe 121 | (generalization to unbalanced panels) 122 | } 123 | \keyword{htest} 124 | -------------------------------------------------------------------------------- /man/pmg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_mg.R 3 | \name{pmg} 4 | \alias{pmg} 5 | \alias{summary.pmg} 6 | \alias{print.summary.pmg} 7 | \alias{residuals.pmg} 8 | \title{Mean Groups (MG), Demeaned MG and CCE MG estimators} 9 | \usage{ 10 | pmg( 11 | formula, 12 | data, 13 | subset, 14 | na.action, 15 | model = c("mg", "cmg", "dmg"), 16 | index = NULL, 17 | trend = FALSE, 18 | ... 19 | ) 20 | 21 | \method{summary}{pmg}(object, ...) 22 | 23 | \method{print}{summary.pmg}( 24 | x, 25 | digits = max(3, getOption("digits") - 2), 26 | width = getOption("width"), 27 | ... 28 | ) 29 | 30 | \method{residuals}{pmg}(object, ...) 31 | } 32 | \arguments{ 33 | \item{formula}{a symbolic description of the model to be estimated,} 34 | 35 | \item{data}{a \code{data.frame},} 36 | 37 | \item{subset}{see \code{\link[=lm]{lm()}},} 38 | 39 | \item{na.action}{see \code{\link[=lm]{lm()}},} 40 | 41 | \item{model}{one of \code{"mg"}, \code{"cmg"}, or \code{"dmg"},} 42 | 43 | \item{index}{the indexes, see \code{\link[=pdata.frame]{pdata.frame()}},} 44 | 45 | \item{trend}{logical specifying whether an individual-specific 46 | trend has to be included,} 47 | 48 | \item{\dots}{further arguments.} 49 | 50 | \item{object, x}{an object of class \code{pmg},} 51 | 52 | \item{digits}{digits,} 53 | 54 | \item{width}{the maximum length of the lines in the print output,} 55 | } 56 | \value{ 57 | An object of class \code{c("pmg", "panelmodel")} containing: 58 | \item{coefficients}{the vector of coefficients,} 59 | \item{residuals}{the vector of residuals,} 60 | \item{fitted.values}{the vector of fitted values,} 61 | \item{vcov}{the covariance matrix of the coefficients,} 62 | \item{df.residual}{degrees of freedom of the residuals,} 63 | \item{model}{a data.frame containing the variables used for the 64 | estimation,} 65 | \item{r.squared}{numeric, the R squared,} 66 | \item{call}{the call,} 67 | \item{indcoef}{the matrix of individual coefficients from 68 | separate time series regressions.} 69 | } 70 | \description{ 71 | Mean Groups (MG), Demeaned MG (DMG) and Common Correlated Effects 72 | MG (CCEMG) estimators for heterogeneous panel models, possibly with 73 | common factors (CCEMG) 74 | } 75 | \details{ 76 | \code{pmg} is a function for the estimation of linear panel models with 77 | heterogeneous coefficients by various Mean Groups estimators. Setting 78 | argument \code{model = "mg"} specifies the standard Mean Groups estimator, based on the 79 | average of individual time series regressions. If \code{model = "dmg"} 80 | the data are demeaned cross-sectionally, which is believed to 81 | reduce the influence of common factors (and is akin to what is done 82 | in homogeneous panels when \code{model = "within"} and \code{effect = "time"}). 83 | Lastly, if \code{model = "cmg"} the CCEMG estimator is 84 | employed which is consistent under the hypothesis of 85 | unobserved common factors and idiosyncratic factor loadings; it 86 | works by augmenting the model by cross-sectional averages of the 87 | dependent variable and regressors in order to account for the 88 | common factors, and adding individual intercepts and possibly 89 | trends. 90 | } 91 | \examples{ 92 | data("Produc", package = "plm") 93 | ## Mean Groups estimator 94 | mgmod <- pmg(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc) 95 | summary(mgmod) 96 | 97 | ## demeaned Mean Groups 98 | dmgmod <- pmg(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, 99 | data = Produc, model = "dmg") 100 | summary(dmgmod) 101 | 102 | ## Common Correlated Effects Mean Groups 103 | ccemgmod <- pmg(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, 104 | data = Produc, model = "cmg") 105 | summary(ccemgmod) 106 | } 107 | \references{ 108 | \insertRef{PESA:06}{plm} 109 | } 110 | \author{ 111 | Giovanni Millo 112 | } 113 | \keyword{regression} 114 | -------------------------------------------------------------------------------- /man/pmodel.response.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_model.extract.R 3 | \name{pmodel.response} 4 | \alias{pmodel.response} 5 | \alias{pmodel.response.plm} 6 | \alias{pmodel.response.data.frame} 7 | \alias{pmodel.response.formula} 8 | \title{A function to extract the model.response} 9 | \usage{ 10 | pmodel.response(object, ...) 11 | 12 | \method{pmodel.response}{plm}(object, ...) 13 | 14 | \method{pmodel.response}{data.frame}(object, ...) 15 | 16 | \method{pmodel.response}{formula}(object, data, ...) 17 | } 18 | \arguments{ 19 | \item{object}{an object of class \code{"plm"}, or a formula of 20 | class \code{"Formula"},} 21 | 22 | \item{\dots}{further arguments.} 23 | 24 | \item{data}{a \code{data.frame}} 25 | } 26 | \value{ 27 | A pseries except if model responses' of a \code{"between"} 28 | or \code{"fd"} model as these models "compress" the data (the number 29 | of observations used in estimation is smaller than the original 30 | data due to the specific transformation). A numeric is returned 31 | for the \code{"between"} and \code{"fd"} model. 32 | } 33 | \description{ 34 | pmodel.response has several methods to conveniently extract the 35 | response of several objects. 36 | } 37 | \details{ 38 | The model response is extracted from a \code{pdata.frame} (where the 39 | response must reside in the first column; this is the case for a 40 | model frame), a \code{Formula} + \code{data} (being a model frame) or a \code{plm} 41 | object, and the 42 | transformation specified by \code{effect} and \code{model} is applied to 43 | it.\cr Constructing the model frame first ensures proper \code{NA} 44 | handling and the response being placed in the first column, see 45 | also \strong{Examples} for usage. 46 | } 47 | \examples{ 48 | 49 | # First, make a pdata.frame 50 | data("Grunfeld", package = "plm") 51 | pGrunfeld <- pdata.frame(Grunfeld) 52 | 53 | # then make a model frame from a Formula and a pdata.frame 54 | form <- inv ~ value + capital 55 | mf <- model.frame(pGrunfeld, form) 56 | 57 | # retrieve (transformed) response directly from model frame 58 | resp_mf <- pmodel.response(mf, model = "within", effect = "individual") 59 | 60 | # retrieve (transformed) response from a plm object, i.e., an estimated model 61 | fe_model <- plm(form, data = pGrunfeld, model = "within") 62 | pmodel.response(fe_model) 63 | 64 | # same as constructed before 65 | all.equal(resp_mf, pmodel.response(fe_model), check.attributes = FALSE) # TRUE 66 | 67 | } 68 | \seealso{ 69 | \code{plm}'s \code{\link[=model.matrix]{model.matrix()}} for (transformed) 70 | model matrix and the corresponding \code{\link[=model.frame]{model.frame()}} 71 | method to construct a model frame. 72 | } 73 | \author{ 74 | Yves Croissant 75 | } 76 | \keyword{manip} 77 | -------------------------------------------------------------------------------- /man/pooltest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_general.R 3 | \name{pooltest} 4 | \alias{pooltest} 5 | \alias{pooltest.plm} 6 | \alias{pooltest.formula} 7 | \title{Test of Poolability} 8 | \usage{ 9 | pooltest(x, ...) 10 | 11 | \method{pooltest}{plm}(x, z, ...) 12 | 13 | \method{pooltest}{formula}(x, data, ...) 14 | } 15 | \arguments{ 16 | \item{x}{an object of class \code{"plm"} for the plm method; an object of 17 | class \code{"formula"} for the formula interface,} 18 | 19 | \item{\dots}{further arguments passed to plm.} 20 | 21 | \item{z}{an object of class \code{"pvcm"} obtained with 22 | \code{model="within"},} 23 | 24 | \item{data}{a \code{data.frame},} 25 | } 26 | \value{ 27 | An object of class \code{"htest"}. 28 | } 29 | \description{ 30 | A Chow test for the poolability of the data. 31 | } 32 | \details{ 33 | \code{pooltest} is a \emph{F} test of stability (or Chow test) for the 34 | coefficients of a panel model. For argument \code{x}, the estimated 35 | \code{plm} object should be a \code{"pooling"} model or a \code{"within"} model 36 | (the default); intercepts are assumed to be identical in the first 37 | case and different in the second case. 38 | } 39 | \examples{ 40 | 41 | data("Gasoline", package = "plm") 42 | form <- lgaspcar ~ lincomep + lrpmg + lcarpcap 43 | gasw <- plm(form, data = Gasoline, model = "within") 44 | gasp <- plm(form, data = Gasoline, model = "pooling") 45 | gasnp <- pvcm(form, data = Gasoline, model = "within") 46 | pooltest(gasw, gasnp) 47 | pooltest(gasp, gasnp) 48 | 49 | pooltest(form, data = Gasoline, effect = "individual", model = "within") 50 | pooltest(form, data = Gasoline, effect = "individual", model = "pooling") 51 | 52 | } 53 | \author{ 54 | Yves Croissant 55 | } 56 | \keyword{htest} 57 | -------------------------------------------------------------------------------- /man/predict.plm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_methods.R 3 | \name{predict.plm} 4 | \alias{predict.plm} 5 | \title{Model Prediction for plm Objects} 6 | \usage{ 7 | \method{predict}{plm}( 8 | object, 9 | newdata = NULL, 10 | na.fill = !inherits(newdata, "pdata.frame"), 11 | ... 12 | ) 13 | } 14 | \arguments{ 15 | \item{object}{An object of class \code{"plm"},} 16 | 17 | \item{newdata}{An optional pdata.frame in which to look for variables to be 18 | used for prediction. If \code{NULL}, the fitted values are returned. 19 | For fixed effects models, supplying a pdata.frame is recommended.} 20 | 21 | \item{na.fill}{A logical, only relevant if \code{object} is a pdata.frame, indicating 22 | whether for any supplied out-of-sample indexes (individual, time, 23 | combination of both), the missing fixed effect estimate is filled 24 | with the weighted mean of the model's present fixed effect estimates 25 | or not.} 26 | 27 | \item{\dots}{further arguments.} 28 | } 29 | \value{ 30 | A numeric (or a pseries if \code{newdata} is a pdata.frame) carrying the 31 | predicted values with length equal to the number of rows as the data 32 | supplied in \code{newdata} and with names the row names of \code{newdata} or, if 33 | \code{newdata = NULL}, the original model's fitted values given in \code{object}. 34 | } 35 | \description{ 36 | Predicted values of response based on plm models. 37 | } 38 | \details{ 39 | \code{predict}calculates predicted values by evaluating the regression function of 40 | a plm model for \code{newdata} or, if \code{newdata = NULL}, it returns the fitted values 41 | the plm model. 42 | 43 | The fixed effects (within) model is somewhat special in prediction as it has 44 | fixed effects estimated per individual, time period (one-way) or both (two-ways 45 | model) which should to be respected when predicting values relating to these 46 | fixed effects in the model: To do so, it is recommended to supply a pdata.frame 47 | (and not a plain data.frame) in \code{newdata} as it describes the relationship 48 | between the data supplied to the individual. and/or time periods. In case 49 | the \code{newdata}´'s pdata.frame has out-of-sample data (data contains individuals 50 | and/or time periods not contained in the original model), it is not clear 51 | how values are to be predicted and the result will contain \code{NA} 52 | values for these out-of-sample data. Argument \code{na.fill} can be set to \code{TRUE} 53 | to apply the original model's weighted mean of fixed effects for the 54 | out-of-sample data to derive a prediction. 55 | 56 | If a plain data.frame is given in \code{newdata} for a fixed effects model, the 57 | weighted mean is used for all fixed effects as \code{newdata} for prediction as a 58 | plain data.frame cannot describe any relation to individuals/time periods 59 | (\code{na.fill} is automatically set to \code{TRUE} and the function warns). 60 | 61 | See also \strong{Examples}. 62 | } 63 | \examples{ 64 | library(plm) 65 | data("Grunfeld", package = "plm") 66 | 67 | # fit a fixed effect model 68 | fit.fe <- plm(inv ~ value + capital, data = Grunfeld, model = "within") 69 | 70 | # generate 55 new observations of three firms used for prediction: 71 | # * firm 1 with years 1935:1964 (has out-of-sample years 1955:1964), 72 | # * firm 2 with years 1935:1949 (all in sample), 73 | # * firm 11 with years 1935:1944 (firm 11 is out-of-sample) 74 | set.seed(42L) 75 | 76 | new.value2 <- runif(55, min = min(Grunfeld$value), max = max(Grunfeld$value)) 77 | new.capital2 <- runif(55, min = min(Grunfeld$capital), max = max(Grunfeld$capital)) 78 | 79 | newdata <- data.frame(firm = c(rep(1, 30), rep(2, 15), rep(11, 10)), 80 | year = c(1935:(1935+29), 1935:(1935+14), 1935:(1935+9)), 81 | value = new.value2, capital = new.capital2) 82 | # make pdata.frame 83 | newdata.p <- pdata.frame(newdata, index = c("firm", "year")) 84 | 85 | ## predict from fixed effect model with new data as pdata.frame 86 | predict(fit.fe, newdata = newdata.p) 87 | 88 | ## set na.fill = TRUE to have the weighted mean used to for fixed effects -> no NA values 89 | predict(fit.fe, newdata = newdata.p, na.fill = TRUE) 90 | 91 | ## predict with plain data.frame from fixed effect model: uses mean fixed effects 92 | ## for prediction and, thus, yields different result with a warning 93 | predict(fit.fe, newdata = newdata) 94 | 95 | } 96 | \keyword{regression} 97 | -------------------------------------------------------------------------------- /man/pseriesfy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_pdata.frame.R 3 | \name{pseriesfy} 4 | \alias{pseriesfy} 5 | \title{Turn all columns of a pdata.frame into class pseries.} 6 | \usage{ 7 | pseriesfy(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{an object of class \code{"pdata.frame"},} 11 | 12 | \item{\dots}{further arguments (currently not used).} 13 | } 14 | \value{ 15 | A pdata.frame like the input pdata.frame but with all columns 16 | turned into pseries. 17 | } 18 | \description{ 19 | This function takes a pdata.frame and turns all of its columns into 20 | objects of class pseries. 21 | } 22 | \details{ 23 | Background: Initially created pdata.frames have as columns the pure/basic 24 | class (e.g., numeric, factor, character). When extracting a column from such 25 | a pdata.frame, the extracted column is turned into a pseries. 26 | 27 | At times, it can be convenient to apply data transformation operations on 28 | such a \code{pseriesfy}-ed pdata.frame, see Examples. 29 | } 30 | \examples{ 31 | library("plm") 32 | data("Grunfeld", package = "plm") 33 | pGrun <- pdata.frame(Grunfeld[ , 1:4], drop.index = TRUE) 34 | pGrun2 <- pseriesfy(pGrun) # pseriesfy-ed pdata.frame 35 | 36 | # compare classes of columns 37 | lapply(pGrun, class) 38 | lapply(pGrun2, class) 39 | 40 | # When using with() 41 | with(pGrun, lag(value)) # dispatches to base R's lag() 42 | with(pGrun2, lag(value)) # dispatches to plm's lag() respect. panel structure 43 | 44 | # When lapply()-ing 45 | lapply(pGrun, lag) # dispatches to base R's lag() 46 | lapply(pGrun2, lag) # dispatches to plm's lag() respect. panel structure 47 | 48 | # as.list(., keep.attributes = TRUE) on a non-pseriesfy-ed 49 | # pdata.frame is similar and dispatches to plm's lag 50 | lapply(as.list(pGrun, keep.attributes = TRUE), lag) 51 | 52 | } 53 | \seealso{ 54 | \code{\link[=pdata.frame]{pdata.frame()}}, \code{\link[=as.list]{as.list()}} 55 | } 56 | \keyword{attribute} 57 | -------------------------------------------------------------------------------- /man/pvar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_misc.R 3 | \name{pvar} 4 | \alias{pvar} 5 | \alias{pvar.matrix} 6 | \alias{pvar.data.frame} 7 | \alias{pvar.pdata.frame} 8 | \alias{pvar.pseries} 9 | \alias{print.pvar} 10 | \title{Check for Cross-Sectional and Time Variation} 11 | \usage{ 12 | pvar(x, ...) 13 | 14 | \method{pvar}{matrix}(x, index = NULL, ...) 15 | 16 | \method{pvar}{data.frame}(x, index = NULL, ...) 17 | 18 | \method{pvar}{pdata.frame}(x, ...) 19 | 20 | \method{pvar}{pseries}(x, ...) 21 | 22 | \method{print}{pvar}(x, ...) 23 | } 24 | \arguments{ 25 | \item{x}{a \verb{(p)data.frame} or a \code{matrix},} 26 | 27 | \item{\dots}{further arguments.} 28 | 29 | \item{index}{see \code{\link[=pdata.frame]{pdata.frame()}},} 30 | } 31 | \value{ 32 | An object of class \code{pvar} containing the following 33 | elements: 34 | 35 | \item{id.variation}{a logical vector with \code{TRUE} values if the 36 | variable has individual variation, \code{FALSE} if not,} 37 | 38 | \item{time.variation}{a logical vector with \code{TRUE} values if the 39 | variable has time variation, \code{FALSE} if not,} 40 | 41 | \item{id.variation_anyNA}{a logical vector with \code{TRUE} values if 42 | the variable has at least one individual-time combination with all 43 | \code{NA} values in the individual dimension for at least one time period, 44 | \code{FALSE} if not,} 45 | 46 | \item{time.variation_anyNA}{a logical vector with \code{TRUE} values if 47 | the variable has at least one individual-time combination with all 48 | \code{NA} values in the time dimension for at least one individual, 49 | \code{FALSE} if not.} 50 | } 51 | \description{ 52 | This function checks for each variable of a panel if it varies 53 | cross-sectionally and over time. 54 | } 55 | \details{ 56 | For (p)data.frame and matrix interface: All-\code{NA} columns are removed 57 | prior to calculation of variation due to coercing to pdata.frame 58 | first. 59 | } 60 | \note{ 61 | \code{pvar} can be time consuming for ``big'' panels. As a fast alternative 62 | \code{\link[collapse:varying]{collapse::varying()}} from package \CRANpkg{collapse} could be used. 63 | } 64 | \examples{ 65 | 66 | 67 | # Gasoline contains two variables which are individual and time 68 | # indexes and are the first two variables 69 | data("Gasoline", package = "plm") 70 | pvar(Gasoline) 71 | 72 | # Hedonic is an unbalanced panel, townid is the individual index; 73 | # the drop.index argument is passed to pdata.frame 74 | data("Hedonic", package = "plm") 75 | pvar(Hedonic, "townid", drop.index = TRUE) 76 | 77 | # same using pdata.frame 78 | Hed <- pdata.frame(Hedonic, "townid", drop.index = TRUE) 79 | pvar(Hed) 80 | 81 | # Gasoline with pvar's matrix interface 82 | Gasoline_mat <- as.matrix(Gasoline) 83 | pvar(Gasoline_mat) 84 | pvar(Gasoline_mat, index=c("country", "year")) 85 | 86 | } 87 | \seealso{ 88 | \code{\link[=pdim]{pdim()}} to check the dimensions of a 'pdata.frame' (and 89 | other objects), 90 | } 91 | \author{ 92 | Yves Croissant 93 | } 94 | \keyword{attribute} 95 | -------------------------------------------------------------------------------- /man/pwartest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_serial.R 3 | \name{pwartest} 4 | \alias{pwartest} 5 | \alias{pwartest.formula} 6 | \alias{pwartest.panelmodel} 7 | \title{Wooldridge Test for AR(1) Errors in FE Panel Models} 8 | \usage{ 9 | pwartest(x, ...) 10 | 11 | \method{pwartest}{formula}(x, data, ...) 12 | 13 | \method{pwartest}{panelmodel}(x, ...) 14 | } 15 | \arguments{ 16 | \item{x}{an object of class \code{formula} or of class \code{panelmodel},} 17 | 18 | \item{\dots}{further arguments to be passed on to \code{vcovHC} (see 19 | Details and Examples).} 20 | 21 | \item{data}{a \code{data.frame},} 22 | } 23 | \value{ 24 | An object of class \code{"htest"}. 25 | } 26 | \description{ 27 | Test of serial correlation for (the idiosyncratic component of) the errors 28 | in fixed--effects panel models. 29 | } 30 | \details{ 31 | As \insertCite{WOOL:10;textual}{plm}, Sec. 10.5.4 observes, under 32 | the null of no serial correlation in the errors, the residuals of a 33 | FE model must be negatively serially correlated, with 34 | \eqn{cor(\hat{u}_{it}, \hat{u}_{is})=-1/(T-1)} for each 35 | \eqn{t,s}. He suggests basing a test for this null hypothesis on a 36 | pooled regression of FE residuals on their first lag: 37 | \eqn{\hat{u}_{i,t} = \alpha + \delta \hat{u}_{i,t-1} + 38 | \eta_{i,t}}. Rejecting the restriction \eqn{\delta = -1/(T-1)} 39 | makes us conclude against the original null of no serial 40 | correlation. 41 | 42 | \code{pwartest} estimates the \code{within} model and retrieves residuals, 43 | then estimates an AR(1) \code{pooling} model on them. The test statistic 44 | is obtained by applying a F test to the latter model to test the 45 | above restriction on \eqn{\delta}, setting the covariance matrix to 46 | \code{vcovHC} with the option \code{method="arellano"} to control for serial 47 | correlation. 48 | 49 | Unlike the \code{\link[=pbgtest]{pbgtest()}} and \code{\link[=pdwtest]{pdwtest()}}, this test does 50 | not rely on large--T asymptotics and has therefore good properties in 51 | ``short'' panels. Furthermore, it is robust to general heteroskedasticity. 52 | } 53 | \examples{ 54 | 55 | data("EmplUK", package = "plm") 56 | pwartest(log(emp) ~ log(wage) + log(capital), data = EmplUK) 57 | 58 | # pass argument 'type' to vcovHC used in test 59 | pwartest(log(emp) ~ log(wage) + log(capital), data = EmplUK, type = "HC3") 60 | 61 | 62 | } 63 | \references{ 64 | \insertRef{WOOL:02}{plm} 65 | 66 | \insertRef{WOOL:10}{plm} 67 | } 68 | \seealso{ 69 | \code{\link[=pwfdtest]{pwfdtest()}}, \code{\link[=pdwtest]{pdwtest()}}, \code{\link[=pbgtest]{pbgtest()}}, \code{\link[=pbltest]{pbltest()}}, 70 | \code{\link[=pbsytest]{pbsytest()}}. 71 | } 72 | \author{ 73 | Giovanni Millo 74 | } 75 | \keyword{htest} 76 | -------------------------------------------------------------------------------- /man/pwfdtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_serial.R 3 | \name{pwfdtest} 4 | \alias{pwfdtest} 5 | \alias{pwfdtest.formula} 6 | \alias{pwfdtest.panelmodel} 7 | \title{Wooldridge first--difference--based test for AR(1) errors in levels 8 | or first--differenced panel models} 9 | \usage{ 10 | pwfdtest(x, ...) 11 | 12 | \method{pwfdtest}{formula}(x, data, ..., h0 = c("fd", "fe")) 13 | 14 | \method{pwfdtest}{panelmodel}(x, ..., h0 = c("fd", "fe")) 15 | } 16 | \arguments{ 17 | \item{x}{an object of class \code{formula} or a \code{"fd"}-model (plm 18 | object),} 19 | 20 | \item{\dots}{further arguments to be passed on to \code{vcovHC} (see Details 21 | and Examples).} 22 | 23 | \item{data}{a \code{data.frame},} 24 | 25 | \item{h0}{the null hypothesis: one of \code{"fd"}, \code{"fe"},} 26 | } 27 | \value{ 28 | An object of class \code{"htest"}. 29 | } 30 | \description{ 31 | First--differencing--based test of serial correlation for (the idiosyncratic 32 | component of) the errors in either levels or first--differenced panel 33 | models. 34 | } 35 | \details{ 36 | As \insertCite{WOOL:10;textual}{plm}, Sec. 10.6.3 observes, if the 37 | idiosyncratic errors in the model in levels are uncorrelated (which 38 | we label hypothesis \code{"fe"}), then the errors of the model in first 39 | differences (FD) must be serially correlated with 40 | \eqn{cor(\hat{e}_{it}, \hat{e}_{is}) = -0.5} for each \eqn{t,s}. If 41 | on the contrary the levels model's errors are a random walk, then 42 | there must be no serial correlation in the FD errors (hypothesis 43 | \code{"fd"}). Both the fixed effects (FE) and the first--differenced 44 | (FD) estimators remain consistent under either assumption, but the 45 | relative efficiency changes: FE is more efficient under \code{"fe"}, FD 46 | under \code{"fd"}. 47 | 48 | Wooldridge (ibid.) suggests basing a test for either hypothesis on 49 | a pooled regression of FD residuals on their first lag: 50 | \eqn{\hat{e}_{i,t}=\alpha + \rho \hat{e}_{i,t-1} + 51 | \eta_{i,t}}. Rejecting the restriction \eqn{\rho = -0.5} makes us 52 | conclude against the null of no serial correlation in errors of the 53 | levels equation (\code{"fe"}). The null hypothesis of no serial 54 | correlation in differenced errors (\code{"fd"}) is tested in a similar 55 | way, but based on the zero restriction on \eqn{\rho} (\eqn{\rho = 56 | 0}). Rejecting \code{"fe"} favours the use of the first--differences 57 | estimator and the contrary, although it is possible that both be 58 | rejected. 59 | 60 | \code{pwfdtest} estimates the \code{fd} model (or takes an \code{fd} model as 61 | input for the panelmodel interface) and retrieves its residuals, 62 | then estimates an AR(1) \code{pooling} model on them. The test statistic 63 | is obtained by applying a F test to the latter model to test the 64 | relevant restriction on \eqn{\rho}, setting the covariance matrix 65 | to \code{vcovHC} with the option \code{method="arellano"} to control for 66 | serial correlation. 67 | 68 | Unlike the \code{pbgtest} and \code{pdwtest}, this test does not rely on 69 | large--T asymptotics and has therefore good properties in ''short'' 70 | panels. Furthermore, it is robust to general 71 | heteroskedasticity. The \code{"fe"} version can be used to test for 72 | error autocorrelation regardless of whether the maintained 73 | specification has fixed or random effects 74 | \insertCite{@see @DRUK:03}{plm}. 75 | } 76 | \examples{ 77 | 78 | data("EmplUK" , package = "plm") 79 | pwfdtest(log(emp) ~ log(wage) + log(capital), data = EmplUK) 80 | pwfdtest(log(emp) ~ log(wage) + log(capital), data = EmplUK, h0 = "fe") 81 | 82 | # pass argument 'type' to vcovHC used in test 83 | pwfdtest(log(emp) ~ log(wage) + log(capital), data = EmplUK, type = "HC3", h0 = "fe") 84 | 85 | 86 | # same with panelmodel interface 87 | mod <- plm(log(emp) ~ log(wage) + log(capital), data = EmplUK, model = "fd") 88 | pwfdtest(mod) 89 | pwfdtest(mod, h0 = "fe") 90 | pwfdtest(mod, type = "HC3", h0 = "fe") 91 | 92 | 93 | } 94 | \references{ 95 | \insertRef{DRUK:03}{plm} 96 | 97 | \insertRef{WOOL:02}{plm} 98 | Sec. 10.6.3, pp. 282--283. 99 | 100 | \insertRef{WOOL:10}{plm} 101 | Sec. 10.6.3, pp. 319--320 102 | } 103 | \seealso{ 104 | \code{pdwtest}, \code{pbgtest}, \code{pwartest}, 105 | } 106 | \author{ 107 | Giovanni Millo 108 | } 109 | \keyword{htest} 110 | -------------------------------------------------------------------------------- /man/pwtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_serial.R 3 | \name{pwtest} 4 | \alias{pwtest} 5 | \alias{pwtest.formula} 6 | \alias{pwtest.panelmodel} 7 | \title{Wooldridge's Test for Unobserved Effects in Panel Models} 8 | \usage{ 9 | pwtest(x, ...) 10 | 11 | \method{pwtest}{formula}(x, data, effect = c("individual", "time"), ...) 12 | 13 | \method{pwtest}{panelmodel}(x, effect = c("individual", "time"), ...) 14 | } 15 | \arguments{ 16 | \item{x}{an object of class \code{"formula"}, or an estimated model of class 17 | \code{panelmodel},} 18 | 19 | \item{\dots}{further arguments passed to \code{plm}.} 20 | 21 | \item{data}{a \code{data.frame},} 22 | 23 | \item{effect}{the effect to be tested for, one of \code{"individual"} 24 | (default) or \code{"time"},} 25 | } 26 | \value{ 27 | An object of class \code{"htest"}. 28 | } 29 | \description{ 30 | Semi-parametric test for the presence of (individual or time) unobserved 31 | effects in panel models. 32 | } 33 | \details{ 34 | This semi-parametric test checks the null hypothesis of zero 35 | correlation between errors of the same group. Therefore, it has 36 | power both against individual effects and, more generally, any kind 37 | of serial correlation. 38 | 39 | The test relies on large-N asymptotics. It is valid under error 40 | heteroskedasticity and departures from normality. 41 | 42 | The above is valid if \code{effect="individual"}, which is the most 43 | likely usage. If \code{effect="time"}, symmetrically, the test relies on 44 | large-T asymptotics and has power against time effects and, more 45 | generally, against cross-sectional correlation. 46 | 47 | If the panelmodel interface is used, the inputted model must be a pooling 48 | model. 49 | } 50 | \examples{ 51 | 52 | data("Produc", package = "plm") 53 | ## formula interface 54 | pwtest(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc) 55 | pwtest(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc, effect = "time") 56 | 57 | ## panelmodel interface 58 | # first, estimate a pooling model, than compute test statistics 59 | form <- formula(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp) 60 | pool_prodc <- plm(form, data = Produc, model = "pooling") 61 | pwtest(pool_prodc) # == effect="individual" 62 | pwtest(pool_prodc, effect="time") 63 | 64 | } 65 | \references{ 66 | \insertRef{WOOL:02}{plm} 67 | 68 | \insertRef{WOOL:10}{plm} 69 | } 70 | \seealso{ 71 | \code{\link[=pbltest]{pbltest()}}, \code{\link[=pbgtest]{pbgtest()}}, 72 | \code{\link[=pdwtest]{pdwtest()}}, \code{\link[=pbsytest]{pbsytest()}}, \code{\link[=pwartest]{pwartest()}}, 73 | \code{\link[=pwfdtest]{pwfdtest()}} for tests for serial correlation in panel models. 74 | \code{\link[=plmtest]{plmtest()}} for tests for random effects. 75 | } 76 | \author{ 77 | Giovanni Millo 78 | } 79 | \keyword{htest} 80 | -------------------------------------------------------------------------------- /man/r.squared.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_plm.R 3 | \name{r.squared} 4 | \alias{r.squared} 5 | \title{R squared and adjusted R squared for panel models} 6 | \usage{ 7 | r.squared(object, model = NULL, type = c("cor", "rss", "ess"), dfcor = FALSE) 8 | } 9 | \arguments{ 10 | \item{object}{an object of class \code{"plm"},} 11 | 12 | \item{model}{on which transformation of the data the R-squared is to be 13 | computed. If \code{NULL}, the transformation used to estimate the model is 14 | also used for the computation of R squared,} 15 | 16 | \item{type}{indicates method which is used to compute R squared. One of\cr 17 | \code{"rss"} (residual sum of squares),\cr \code{"ess"} (explained sum of 18 | squares), or\cr \code{"cor"} (coefficient of correlation between the fitted 19 | values and the response),} 20 | 21 | \item{dfcor}{if \code{TRUE}, the adjusted R squared is computed.} 22 | } 23 | \value{ 24 | A numerical value. The R squared or adjusted R squared of the model 25 | estimated on the transformed data, e. g., for the within model the so called 26 | "within R squared". 27 | } 28 | \description{ 29 | This function computes R squared or adjusted R squared for plm objects. It 30 | allows to define on which transformation of the data the (adjusted) R 31 | squared is to be computed and which method for calculation is used. 32 | } 33 | \examples{ 34 | 35 | data("Grunfeld", package = "plm") 36 | p <- plm(inv ~ value + capital, data = Grunfeld, model = "pooling") 37 | r.squared(p) 38 | r.squared(p, dfcor = TRUE) 39 | 40 | } 41 | \seealso{ 42 | \code{\link[=plm]{plm()}} for estimation of various models; 43 | \code{\link[=summary.plm]{summary.plm()}} which makes use of \code{r.squared}. 44 | } 45 | \keyword{htest} 46 | -------------------------------------------------------------------------------- /man/ranef.plm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_ranfixef.R 3 | \name{ranef.plm} 4 | \alias{ranef.plm} 5 | \alias{ranef} 6 | \title{Extract the Random Effects} 7 | \usage{ 8 | \method{ranef}{plm}(object, effect = NULL, ...) 9 | } 10 | \arguments{ 11 | \item{object}{an object of class \code{"plm"}, needs to be a fitted 12 | random effects model,} 13 | 14 | \item{effect}{\code{NULL}, \code{"individual"}, or \code{"time"}, the effects to 15 | be extracted, see \strong{Details},} 16 | 17 | \item{\dots}{further arguments (currently not used).} 18 | } 19 | \value{ 20 | A named numeric with the random effects per dimension 21 | (individual or time). 22 | } 23 | \description{ 24 | Function to calculate the random effects from a \code{plm} object 25 | (random effects model). 26 | } 27 | \details{ 28 | Function \code{ranef} calculates the random effects of a fitted random 29 | effects model. For one-way models, the effects of the estimated 30 | model are extracted (either individual or time effects). For 31 | two-way models, extracting the individual effects is the default 32 | (both, argument \code{effect = NULL} and \code{effect = "individual"} will 33 | give individual effects). Time effects can be extracted by setting 34 | \code{effect = "time"}. 35 | 36 | Not all random effect model types are supported (yet?). 37 | } 38 | \examples{ 39 | 40 | data("Grunfeld", package = "plm") 41 | m1 <- plm(inv ~ value + capital, data = Grunfeld, model = "random") 42 | ranef(m1) # individual random effects 43 | 44 | # compare to random effects by ML estimation via lme from package nlme 45 | library(nlme) 46 | m2 <- lme(inv ~ value + capital, random = ~1|firm, data = Grunfeld) 47 | cbind("plm" = ranef(m1), "lme" = unname(ranef(m2))) 48 | 49 | # two-ways RE model, calculate individual and time random effects 50 | data("Cigar", package = "plm") 51 | tw <- plm(sales ~ pop + price, data = Cigar, model = "random", effect = "twoways") 52 | ranef(tw) # individual random effects 53 | ranef(tw, effect = "time") # time random effects 54 | 55 | } 56 | \seealso{ 57 | \code{\link[=fixef]{fixef()}} to extract the fixed effects from a fixed 58 | effects model (within model). 59 | } 60 | \author{ 61 | Kevin Tappe 62 | } 63 | \keyword{regression} 64 | -------------------------------------------------------------------------------- /man/re-export_functions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plm-package.R 3 | \name{re-export_functions} 4 | \alias{re-export_functions} 5 | \alias{maxLik} 6 | \title{Functions exported from other packages} 7 | \description{ 8 | These functions are imported from other packages and re-exported by 9 | \pkg{plm} to enable smooth use within \pkg{plm}. Please follow the 10 | links to view the function's original documentation. 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/sargan.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_gmm.R 3 | \name{sargan} 4 | \alias{sargan} 5 | \alias{sargan.pgmm} 6 | \title{Hansen--Sargan Test of Overidentifying Restrictions} 7 | \usage{ 8 | sargan(object, ...) 9 | 10 | \method{sargan}{pgmm}(object, weights = c("twosteps", "onestep"), ...) 11 | } 12 | \arguments{ 13 | \item{object}{an object of class \code{"pgmm"},} 14 | 15 | \item{\dots}{further arguments (currently unused).} 16 | 17 | \item{weights}{the weighting matrix to be used for the computation of the 18 | test,} 19 | } 20 | \value{ 21 | An object of class \code{"htest"}. 22 | } 23 | \description{ 24 | A test of overidentifying restrictions for models estimated by GMM. 25 | } 26 | \details{ 27 | The Hansen--Sargan test ("J test") calculates the quadratic form of the moment 28 | restrictions that is minimized while computing the GMM estimator. It follows 29 | asymptotically a chi-square distribution with number of degrees of freedom 30 | equal to the difference between the number of moment conditions and the 31 | number of coefficients. 32 | } 33 | \examples{ 34 | 35 | data("EmplUK", package = "plm") 36 | ar <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1) + 37 | lag(log(capital), 0:2) + lag(log(output), 0:2) | lag(log(emp), 2:99), 38 | data = EmplUK, effect = "twoways", model = "twosteps") 39 | sargan(ar) 40 | 41 | } 42 | \references{ 43 | \insertCite{HANS:82}{plm} 44 | 45 | \insertCite{SARG:58}{plm} 46 | } 47 | \seealso{ 48 | \code{\link[=pgmm]{pgmm()}} 49 | } 50 | \author{ 51 | Yves Croissant 52 | } 53 | \keyword{htest} 54 | -------------------------------------------------------------------------------- /man/summary.plm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/est_plm.list.R, R/tool_methods.R 3 | \name{summary.plm.list} 4 | \alias{summary.plm.list} 5 | \alias{coef.summary.plm.list} 6 | \alias{print.summary.plm.list} 7 | \alias{summary.plm} 8 | \alias{print.summary.plm} 9 | \title{Summary for plm objects} 10 | \usage{ 11 | \method{summary}{plm.list}(object, ...) 12 | 13 | \method{coef}{summary.plm.list}(object, eq = NULL, ...) 14 | 15 | \method{print}{summary.plm.list}( 16 | x, 17 | digits = max(3, getOption("digits") - 2), 18 | width = getOption("width"), 19 | ... 20 | ) 21 | 22 | \method{summary}{plm}(object, vcov = NULL, ...) 23 | 24 | \method{print}{summary.plm}( 25 | x, 26 | digits = max(3, getOption("digits") - 2), 27 | width = getOption("width"), 28 | subset = NULL, 29 | ... 30 | ) 31 | } 32 | \arguments{ 33 | \item{object}{an object of class \code{"plm"},} 34 | 35 | \item{\dots}{further arguments.} 36 | 37 | \item{eq}{the selected equation for list objects} 38 | 39 | \item{x}{an object of class \code{"summary.plm"},} 40 | 41 | \item{digits}{number of digits for printed output,} 42 | 43 | \item{width}{the maximum length of the lines in the printed output,} 44 | 45 | \item{vcov}{a variance--covariance matrix furnished by the user or 46 | a function to calculate one (see \strong{Examples}),} 47 | 48 | \item{subset}{a character or numeric vector indicating a subset of 49 | the table of coefficients to be printed for 50 | \code{"print.summary.plm"},} 51 | } 52 | \value{ 53 | An object of class \code{c("summary.plm", "plm", "panelmodel")}. Some of its elements are carried over from the 54 | associated plm object and described there 55 | (\code{\link[=plm]{plm()}}). The following elements are new or changed 56 | relative to the elements of a plm object: 57 | 58 | \item{fstatistic}{'htest' object: joint test of significance of 59 | coefficients (F or Chi-square test) (robust statistic in case of 60 | supplied argument \code{vcov}, see \code{\link[=pwaldtest]{pwaldtest()}} for details),} 61 | 62 | \item{coefficients}{a matrix with the estimated coefficients, 63 | standard errors, t--values, and p--values, if argument \code{vcov} was 64 | set to non-\code{NULL} the standard errors (and t-- and p--values) in 65 | their respective robust variant,} 66 | 67 | \item{vcov}{the "regular" variance--covariance matrix of the coefficients (class "matrix"),} 68 | 69 | \item{rvcov}{only present if argument \code{vcov} was set to non-\code{NULL}: 70 | the furnished variance--covariance matrix of the coefficients 71 | (class "matrix"),} 72 | 73 | \item{r.squared}{a named numeric containing the R-squared ("rsq") 74 | and the adjusted R-squared ("adjrsq") of the model,} 75 | 76 | \item{df}{an integer vector with 3 components, (p, n-p, p*), where 77 | p is the number of estimated (non-aliased) coefficients of the 78 | model, n-p are the residual degrees of freedom (n being number of 79 | observations), and p* is the total number of coefficients 80 | (incl. any aliased ones).} 81 | } 82 | \description{ 83 | The summary method for plm objects generates some more information about 84 | estimated plm models. 85 | } 86 | \details{ 87 | The \code{summary} method for plm objects (\code{summary.plm}) creates an 88 | object of class \code{c("summary.plm", "plm", "panelmodel")} that 89 | extends the plm object it is run on with various information about 90 | the estimated model like (inferential) statistics, see 91 | \strong{Value}. It has an associated print method 92 | (\code{print.summary.plm}). 93 | } 94 | \examples{ 95 | 96 | data("Produc", package = "plm") 97 | zz <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, 98 | data = Produc, index = c("state","year")) 99 | summary(zz) 100 | 101 | # summary with a furnished vcov, passed as matrix, as function, and 102 | # as function with additional argument 103 | data("Grunfeld", package = "plm") 104 | wi <- plm(inv ~ value + capital, 105 | data = Grunfeld, model="within", effect = "individual") 106 | summary(wi, vcov = vcovHC(wi)) 107 | summary(wi, vcov = vcovHC) 108 | summary(wi, vcov = function(x) vcovHC(x, method = "white2")) 109 | 110 | # extract F statistic 111 | wi_summary <- summary(wi) 112 | Fstat <- wi_summary[["fstatistic"]] 113 | 114 | # extract estimates and p-values 115 | est <- wi_summary[["coefficients"]][ , "Estimate"] 116 | pval <- wi_summary[["coefficients"]][ , "Pr(>|t|)"] 117 | 118 | # print summary only for coefficient "value" 119 | print(wi_summary, subset = "value") 120 | 121 | } 122 | \seealso{ 123 | \code{\link[=plm]{plm()}} for estimation of various models; \code{\link[=vcovHC]{vcovHC()}} for 124 | an example of a robust estimation of variance--covariance 125 | matrix; \code{\link[=r.squared]{r.squared()}} for the function to calculate R-squared; 126 | \code{\link[stats:print.power.htest]{stats::print.power.htest()}} for some information about class 127 | "htest"; \code{\link[=fixef]{fixef()}} to compute the fixed effects for "within" 128 | (=fixed effects) models and \code{\link[=within_intercept]{within_intercept()}} for an 129 | "overall intercept" for such models; \code{\link[=pwaldtest]{pwaldtest()}} 130 | } 131 | \author{ 132 | Yves Croissant 133 | } 134 | \keyword{regression} 135 | -------------------------------------------------------------------------------- /man/vcovBK.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_vcovG.R 3 | \name{vcovBK} 4 | \alias{vcovBK} 5 | \alias{vcovBK.plm} 6 | \title{Beck and Katz Robust Covariance Matrix Estimators} 7 | \usage{ 8 | vcovBK(x, ...) 9 | 10 | \method{vcovBK}{plm}( 11 | x, 12 | type = c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"), 13 | cluster = c("group", "time"), 14 | diagonal = FALSE, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{x}{an object of class \code{"plm"},} 20 | 21 | \item{\dots}{further arguments.} 22 | 23 | \item{type}{the weighting scheme used, one of \code{"HC0"}, \code{"sss"}, \code{"HC1"}, 24 | \code{"HC2"}, \code{"HC3"}, \code{"HC4"}, see Details,} 25 | 26 | \item{cluster}{one of \code{"group"}, \code{"time"},} 27 | 28 | \item{diagonal}{a logical value specifying whether to force 29 | non-diagonal elements to zero,} 30 | } 31 | \value{ 32 | An object of class \code{"matrix"} containing the estimate of 33 | the covariance matrix of coefficients. 34 | } 35 | \description{ 36 | Unconditional Robust covariance matrix estimators \emph{a la Beck 37 | and Katz} for panel models (a.k.a. Panel Corrected Standard Errors 38 | (PCSE)). 39 | } 40 | \details{ 41 | \code{vcovBK} is a function for estimating a robust covariance matrix of 42 | parameters for a panel model according to the 43 | \insertCite{BECK:KATZ:95;textual}{plm} method, a.k.a. Panel 44 | Corrected Standard Errors (PCSE), which uses an unconditional 45 | estimate of the error covariance across time periods (groups) 46 | inside the standard formula for coefficient 47 | covariance. Observations may be clustered either by \code{"group"} to 48 | account for timewise heteroskedasticity and serial correlation or 49 | by \code{"time"} to account for cross-sectional heteroskedasticity and 50 | correlation. It must be borne in mind that the Beck and Katz 51 | formula is based on N- (T-) asymptotics and will not be appropriate 52 | elsewhere. 53 | 54 | The \code{diagonal} logical argument can be used, if set to 55 | \code{TRUE}, to force to zero all non-diagonal elements in the 56 | estimated error covariances; this is appropriate if both serial and 57 | cross--sectional correlation are assumed out, and yields a 58 | timewise- (groupwise-) heteroskedasticity--consistent estimator. 59 | 60 | Weighting schemes specified by \code{type} are analogous to those in 61 | \code{\link[sandwich:vcovHC]{sandwich::vcovHC()}} in package \CRANpkg{sandwich} and are 62 | justified theoretically (although in the context of the standard 63 | linear model) by \insertCite{MACK:WHIT:85;textual}{plm} and 64 | \insertCite{CRIB:04;textual}{plm} \insertCite{@see @ZEIL:04}{plm}. 65 | 66 | The main use of \code{vcovBK} (and the other variance-covariance estimators 67 | provided in the package \code{vcovHC}, \code{vcovNW}, \code{vcovDC}, \code{vcovSCC}) is to pass 68 | it to plm's own functions like \code{summary}, \code{pwaldtest}, and \code{phtest} or 69 | together with testing functions from the \code{lmtest} and \code{car} packages. All of 70 | these typically allow passing the \code{vcov} or \code{vcov.} parameter either as a 71 | matrix or as a function, e.g., for Wald--type testing: argument \code{vcov.} to 72 | \code{coeftest()}, argument \code{vcov} to \code{waldtest()} and other methods in the 73 | \CRANpkg{lmtest} package; and argument \code{vcov.} to 74 | \code{linearHypothesis()} in the \CRANpkg{car} package (see the 75 | examples), see \insertCite{@see also @ZEIL:04}{plm}, 4.1-2, and examples below. 76 | } 77 | \examples{ 78 | 79 | data("Produc", package="plm") 80 | zz <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp, data=Produc, model="random") 81 | summary(zz, vcov = vcovBK) 82 | summary(zz, vcov = function(x) vcovBK(x, type="HC1")) 83 | 84 | ## standard coefficient significance test 85 | library(lmtest) 86 | coeftest(zz) 87 | ## robust significance test, cluster by group 88 | ## (robust vs. serial correlation), default arguments 89 | coeftest(zz, vcov.=vcovBK) 90 | ## idem with parameters, pass vcov as a function argument 91 | coeftest(zz, vcov.=function(x) vcovBK(x, type="HC1")) 92 | ## idem, cluster by time period 93 | ## (robust vs. cross-sectional correlation) 94 | coeftest(zz, vcov.=function(x) vcovBK(x, type="HC1", cluster="time")) 95 | ## idem with parameters, pass vcov as a matrix argument 96 | coeftest(zz, vcov.=vcovBK(zz, type="HC1")) 97 | ## joint restriction test 98 | waldtest(zz, update(zz, .~.-log(emp)-unemp), vcov=vcovBK) 99 | \dontrun{ 100 | ## test of hyp.: 2*log(pc)=log(emp) 101 | library(car) 102 | linearHypothesis(zz, "2*log(pc)=log(emp)", vcov.=vcovBK) 103 | } 104 | } 105 | \references{ 106 | \insertRef{BECK:KATZ:95}{plm} 107 | 108 | \insertRef{CRIB:04}{plm} 109 | 110 | \insertRef{GREE:03}{plm} 111 | 112 | \insertRef{MACK:WHIT:85}{plm} 113 | 114 | \insertRef{ZEIL:04}{plm} 115 | } 116 | \seealso{ 117 | \code{\link[sandwich:vcovHC]{sandwich::vcovHC()}} from the \CRANpkg{sandwich} 118 | package for weighting schemes (\code{type} argument). 119 | } 120 | \author{ 121 | Giovanni Millo 122 | } 123 | \keyword{regression} 124 | -------------------------------------------------------------------------------- /man/vcovDC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_vcovG.R 3 | \name{vcovDC} 4 | \alias{vcovDC} 5 | \alias{vcovDC.plm} 6 | \title{Double-Clustering Robust Covariance Matrix Estimator} 7 | \usage{ 8 | vcovDC(x, ...) 9 | 10 | \method{vcovDC}{plm}(x, type = c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"), ...) 11 | } 12 | \arguments{ 13 | \item{x}{an object of class \code{"plm"} or \code{"pcce"}} 14 | 15 | \item{\dots}{further arguments} 16 | 17 | \item{type}{the weighting scheme used, one of \code{"HC0"}, \code{"sss"}, 18 | \code{"HC1"}, \code{"HC2"}, \code{"HC3"}, \code{"HC4"}, see Details,} 19 | } 20 | \value{ 21 | An object of class \code{"matrix"} containing the estimate of 22 | the covariance matrix of coefficients. 23 | } 24 | \description{ 25 | High-level convenience wrapper for double-clustering robust 26 | covariance matrix estimators \emph{a la} 27 | \insertCite{THOM:11;textual}{plm} and 28 | \insertCite{CAME:GELB:MILL:11;textual}{plm} for panel models. 29 | } 30 | \details{ 31 | \code{vcovDC} is a function for estimating a robust covariance matrix of 32 | parameters for a panel model with errors clustering along both dimensions. 33 | The function is a convenience wrapper simply summing a group- and a 34 | time-clustered covariance matrix and subtracting a diagonal one \emph{a la} 35 | White. 36 | 37 | Weighting schemes specified by \code{type} are analogous to those in 38 | \code{\link[sandwich:vcovHC]{sandwich::vcovHC()}} in package \CRANpkg{sandwich} and are 39 | justified theoretically (although in the context of the standard 40 | linear model) by \insertCite{MACK:WHIT:85;textual}{plm} and 41 | \insertCite{CRIB:04;textual}{plm} \insertCite{@see @ZEIL:04}{plm}. 42 | 43 | The main use of \code{vcovDC} (and the other variance-covariance estimators 44 | provided in the package \code{vcovHC}, \code{vcovBK}, \code{vcovNW}, \code{vcovSCC}) is to pass 45 | it to plm's own functions like \code{summary}, \code{pwaldtest}, and \code{phtest} or 46 | together with testing functions from the \code{lmtest} and \code{car} packages. All of 47 | these typically allow passing the \code{vcov} or \code{vcov.} parameter either as a 48 | matrix or as a function, e.g., for Wald--type testing: argument \code{vcov.} to 49 | \code{coeftest()}, argument \code{vcov} to \code{waldtest()} and other methods in the 50 | \CRANpkg{lmtest} package; and argument \code{vcov.} to 51 | \code{linearHypothesis()} in the \CRANpkg{car} package (see the 52 | examples), see \insertCite{@see also @ZEIL:04}{plm}, 4.1-2, and examples below. 53 | } 54 | \examples{ 55 | 56 | data("Produc", package="plm") 57 | zz <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp, data=Produc, model="pooling") 58 | ## as function input to plm's summary method (with and without additional arguments): 59 | summary(zz, vcov = vcovDC) 60 | summary(zz, vcov = function(x) vcovDC(x, type="HC1", maxlag=4)) 61 | ## standard coefficient significance test 62 | library(lmtest) 63 | coeftest(zz) 64 | ## DC robust significance test, default 65 | coeftest(zz, vcov.=vcovDC) 66 | ## idem with parameters, pass vcov as a function argument 67 | coeftest(zz, vcov.=function(x) vcovDC(x, type="HC1", maxlag=4)) 68 | ## joint restriction test 69 | waldtest(zz, update(zz, .~.-log(emp)-unemp), vcov=vcovDC) 70 | \dontrun{ 71 | ## test of hyp.: 2*log(pc)=log(emp) 72 | library(car) 73 | linearHypothesis(zz, "2*log(pc)=log(emp)", vcov.=vcovDC) 74 | } 75 | } 76 | \references{ 77 | \insertRef{CAME:GELB:MILL:11}{plm} 78 | 79 | \insertRef{CRIB:04}{plm} 80 | 81 | \insertRef{MACK:WHIT:85}{plm} 82 | 83 | \insertRef{THOM:11}{plm} 84 | 85 | \insertRef{ZEIL:04}{plm} 86 | } 87 | \seealso{ 88 | \code{\link[sandwich:vcovHC]{sandwich::vcovHC()}} from the \CRANpkg{sandwich} 89 | package for weighting schemes (\code{type} argument). 90 | } 91 | \author{ 92 | Giovanni Millo 93 | } 94 | \keyword{regression} 95 | -------------------------------------------------------------------------------- /man/vcovG.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_vcovG.R 3 | \name{vcovG} 4 | \alias{vcovG} 5 | \alias{vcovG.plm} 6 | \alias{vcovG.pcce} 7 | \title{Generic Lego building block for Robust Covariance Matrix Estimators} 8 | \usage{ 9 | vcovG(x, ...) 10 | 11 | \method{vcovG}{plm}( 12 | x, 13 | type = c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"), 14 | cluster = c("group", "time"), 15 | l = 0, 16 | inner = c("cluster", "white", "diagavg"), 17 | ... 18 | ) 19 | 20 | \method{vcovG}{pcce}( 21 | x, 22 | type = c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"), 23 | cluster = c("group", "time"), 24 | l = 0, 25 | inner = c("cluster", "white", "diagavg"), 26 | ... 27 | ) 28 | } 29 | \arguments{ 30 | \item{x}{an object of class \code{"plm"} or \code{"pcce"}} 31 | 32 | \item{\dots}{further arguments} 33 | 34 | \item{type}{the weighting scheme used, one of \code{"HC0"}, 35 | \code{"sss"}, \code{"HC1"}, \code{"HC2"}, \code{"HC3"}, \code{"HC4"},} 36 | 37 | \item{cluster}{one of \code{"group"}, \code{"time"},} 38 | 39 | \item{l}{lagging order, defaulting to zero} 40 | 41 | \item{inner}{the function to be applied to the residuals inside the 42 | sandwich: one of \code{"cluster"} or \code{"white"} or 43 | \code{"diagavg"}, or a user specified R function,} 44 | } 45 | \value{ 46 | An object of class \code{"matrix"} containing the estimate 47 | of the covariance matrix of coefficients. 48 | } 49 | \description{ 50 | Generic Lego building block for robust covariance matrix estimators 51 | of the vcovXX kind for panel models. 52 | } 53 | \details{ 54 | \code{vcovG} is the generic building block for use by higher--level 55 | wrappers \code{\link[=vcovHC]{vcovHC()}}, \code{\link[=vcovSCC]{vcovSCC()}}, \code{\link[=vcovDC]{vcovDC()}}, and \code{\link[=vcovNW]{vcovNW()}}. The 56 | main use of \code{vcovG} is to be used internally by the former, but it 57 | is made available in the user space for use in non--standard 58 | combinations. For more documentation, see see wrapper functions 59 | mentioned. 60 | } 61 | \examples{ 62 | 63 | data("Produc", package="plm") 64 | zz <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp, data=Produc, 65 | model="pooling") 66 | ## reproduce Arellano's covariance matrix 67 | vcovG(zz, cluster="group", inner="cluster", l=0) 68 | ## define custom covariance function 69 | ## (in this example, same as vcovHC) 70 | myvcov <- function(x) vcovG(x, cluster="group", inner="cluster", l=0) 71 | summary(zz, vcov = myvcov) 72 | ## use in coefficient significance test 73 | library(lmtest) 74 | ## robust significance test 75 | coeftest(zz, vcov. = myvcov) 76 | 77 | } 78 | \references{ 79 | \insertRef{mil17b}{plm} 80 | } 81 | \seealso{ 82 | \code{\link[=vcovHC]{vcovHC()}}, \code{\link[=vcovSCC]{vcovSCC()}}, 83 | \code{\link[=vcovDC]{vcovDC()}}, \code{\link[=vcovNW]{vcovNW()}}, and 84 | \code{\link[=vcovBK]{vcovBK()}} albeit the latter does not make use of vcovG. 85 | } 86 | \author{ 87 | Giovanni Millo 88 | } 89 | \keyword{regression} 90 | -------------------------------------------------------------------------------- /man/vcovNW.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_vcovG.R 3 | \name{vcovNW} 4 | \alias{vcovNW} 5 | \alias{vcovNW.plm} 6 | \alias{vcovNW.pcce} 7 | \title{Newey and West (1987) Robust Covariance Matrix Estimator} 8 | \usage{ 9 | vcovNW(x, ...) 10 | 11 | \method{vcovNW}{plm}( 12 | x, 13 | type = c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"), 14 | maxlag = NULL, 15 | wj = function(j, maxlag) 1 - j/(maxlag + 1), 16 | ... 17 | ) 18 | 19 | \method{vcovNW}{pcce}( 20 | x, 21 | type = c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"), 22 | maxlag = NULL, 23 | wj = function(j, maxlag) 1 - j/(maxlag + 1), 24 | ... 25 | ) 26 | } 27 | \arguments{ 28 | \item{x}{an object of class \code{"plm"} or \code{"pcce"}} 29 | 30 | \item{\dots}{further arguments} 31 | 32 | \item{type}{the weighting scheme used, one of \code{"HC0"}, \code{"sss"}, 33 | \code{"HC1"}, \code{"HC2"}, \code{"HC3"}, \code{"HC4"}, see Details,} 34 | 35 | \item{maxlag}{either \code{NULL} or a positive integer specifying the 36 | maximum lag order before truncation} 37 | 38 | \item{wj}{weighting function to be applied to lagged terms,} 39 | } 40 | \value{ 41 | An object of class \code{"matrix"} containing the estimate of 42 | the covariance matrix of coefficients. 43 | } 44 | \description{ 45 | Nonparametric robust covariance matrix estimators \emph{a la Newey 46 | and West} for panel models with serial correlation. 47 | } 48 | \details{ 49 | \code{vcovNW} is a function for estimating a robust covariance matrix of 50 | parameters for a panel model according to the 51 | \insertCite{NEWE:WEST:87;textual}{plm} method. The function works 52 | as a restriction of the \insertCite{DRIS:KRAA:98;textual}{plm} covariance (see 53 | \code{\link[=vcovSCC]{vcovSCC()}}) to no cross--sectional correlation. 54 | 55 | Weighting schemes specified by \code{type} are analogous to those in 56 | \code{\link[sandwich:vcovHC]{sandwich::vcovHC()}} in package \CRANpkg{sandwich} and are 57 | justified theoretically (although in the context of the standard 58 | linear model) by \insertCite{MACK:WHIT:85;textual}{plm} and 59 | \insertCite{CRIB:04;textual}{plm} \insertCite{@see @ZEIL:04}{plm}. 60 | 61 | The main use of \code{vcovNW} (and the other variance-covariance estimators 62 | provided in the package \code{vcovHC}, \code{vcovBK}, \code{vcovDC}, \code{vcovSCC}) is to pass 63 | it to plm's own functions like \code{summary}, \code{pwaldtest}, and \code{phtest} or 64 | together with testing functions from the \code{lmtest} and \code{car} packages. All of 65 | these typically allow passing the \code{vcov} or \code{vcov.} parameter either as a 66 | matrix or as a function, e.g., for Wald--type testing: argument \code{vcov.} to 67 | \code{coeftest()}, argument \code{vcov} to \code{waldtest()} and other methods in the 68 | \CRANpkg{lmtest} package; and argument \code{vcov.} to 69 | \code{linearHypothesis()} in the \CRANpkg{car} package (see the 70 | examples), see \insertCite{@see also @ZEIL:04}{plm}, 4.1-2, and examples below. 71 | } 72 | \examples{ 73 | 74 | data("Produc", package="plm") 75 | zz <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp, data=Produc, model="pooling") 76 | ## as function input to plm's summary method (with and without additional arguments): 77 | summary(zz, vcov = vcovNW) 78 | summary(zz, vcov = function(x) vcovNW(x, method="arellano", type="HC1")) 79 | ## standard coefficient significance test 80 | library(lmtest) 81 | coeftest(zz) 82 | ## NW robust significance test, default 83 | coeftest(zz, vcov.=vcovNW) 84 | ## idem with parameters, pass vcov as a function argument 85 | coeftest(zz, vcov.=function(x) vcovNW(x, type="HC1", maxlag=4)) 86 | ## joint restriction test 87 | waldtest(zz, update(zz, .~.-log(emp)-unemp), vcov=vcovNW) 88 | \dontrun{ 89 | ## test of hyp.: 2*log(pc)=log(emp) 90 | library(car) 91 | linearHypothesis(zz, "2*log(pc)=log(emp)", vcov.=vcovNW) 92 | } 93 | } 94 | \references{ 95 | \insertRef{CRIB:04}{plm} 96 | 97 | \insertRef{DRIS:KRAA:98}{plm} 98 | 99 | \insertRef{MACK:WHIT:85}{plm} 100 | 101 | \insertRef{NEWE:WEST:87}{plm} 102 | 103 | \insertRef{ZEIL:04}{plm} 104 | } 105 | \seealso{ 106 | \code{\link[sandwich:vcovHC]{sandwich::vcovHC()}} from the \CRANpkg{sandwich} package 107 | for weighting schemes (\code{type} argument). 108 | } 109 | \author{ 110 | Giovanni Millo 111 | } 112 | \keyword{regression} 113 | -------------------------------------------------------------------------------- /man/vcovSCC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_vcovG.R 3 | \name{vcovSCC} 4 | \alias{vcovSCC} 5 | \alias{vcovSCC.plm} 6 | \alias{vcovSCC.pcce} 7 | \title{Driscoll and Kraay (1998) Robust Covariance Matrix Estimator} 8 | \usage{ 9 | vcovSCC(x, ...) 10 | 11 | \method{vcovSCC}{plm}( 12 | x, 13 | type = c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"), 14 | cluster = "time", 15 | maxlag = NULL, 16 | inner = c("cluster", "white", "diagavg"), 17 | wj = function(j, maxlag) 1 - j/(maxlag + 1), 18 | ... 19 | ) 20 | 21 | \method{vcovSCC}{pcce}( 22 | x, 23 | type = c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"), 24 | cluster = "time", 25 | maxlag = NULL, 26 | inner = c("cluster", "white", "diagavg"), 27 | wj = function(j, maxlag) 1 - j/(maxlag + 1), 28 | ... 29 | ) 30 | } 31 | \arguments{ 32 | \item{x}{an object of class \code{"plm"} or \code{"pcce"}} 33 | 34 | \item{\dots}{further arguments} 35 | 36 | \item{type}{the weighting scheme used, one of \code{"HC0"}, \code{"sss"}, 37 | \code{"HC1"}, \code{"HC2"}, \code{"HC3"}, \code{"HC4"}, see Details,} 38 | 39 | \item{cluster}{switch for vcovG; set at \code{"time"} here,} 40 | 41 | \item{maxlag}{either \code{NULL} or a positive integer specifying the 42 | maximum lag order before truncation} 43 | 44 | \item{inner}{the function to be applied to the residuals inside the 45 | sandwich: \code{"cluster"} for SCC, \code{"white"} for Newey-West, 46 | (\code{"diagavg"} for compatibility reasons)} 47 | 48 | \item{wj}{weighting function to be applied to lagged terms,} 49 | } 50 | \value{ 51 | An object of class \code{"matrix"} containing the estimate of 52 | the covariance matrix of coefficients. 53 | } 54 | \description{ 55 | Nonparametric robust covariance matrix estimators \emph{a la 56 | Driscoll and Kraay} for panel models with cross-sectional 57 | \emph{and} serial correlation. 58 | } 59 | \details{ 60 | \code{vcovSCC} is a function for estimating a robust covariance matrix 61 | of parameters for a panel model according to the 62 | \insertCite{DRIS:KRAA:98;textual}{plm} method, which is consistent 63 | with cross--sectional and serial correlation in a T-asymptotic 64 | setting and irrespective of the N dimension. The use with random 65 | effects models is undocumented. 66 | 67 | Weighting schemes specified by \code{type} are analogous to those in 68 | \code{\link[sandwich:vcovHC]{sandwich::vcovHC()}} in package \CRANpkg{sandwich} and are 69 | justified theoretically (although in the context of the standard 70 | linear model) by \insertCite{MACK:WHIT:85;textual}{plm} and 71 | \insertCite{CRIB:04;textual}{plm} \insertCite{@see @ZEIL:04}{plm}). 72 | 73 | The main use of \code{vcovSCC} (and the other variance-covariance estimators 74 | provided in the package \code{vcovHC}, \code{vcovBK}, \code{vcovNW}, \code{vcovDC}) is to pass 75 | it to plm's own functions like \code{summary}, \code{pwaldtest}, and \code{phtest} or 76 | together with testing functions from the \code{lmtest} and \code{car} packages. All of 77 | these typically allow passing the \code{vcov} or \code{vcov.} parameter either as a 78 | matrix or as a function, e.g., for Wald--type testing: argument \code{vcov.} to 79 | \code{coeftest()}, argument \code{vcov} to \code{waldtest()} and other methods in the 80 | \CRANpkg{lmtest} package; and argument \code{vcov.} to 81 | \code{linearHypothesis()} in the \CRANpkg{car} package (see the 82 | examples), \insertCite{@see also @ZEIL:04}{plm}, 4.1-2, and examples below. 83 | } 84 | \examples{ 85 | 86 | data("Produc", package="plm") 87 | zz <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp, data=Produc, model="pooling") 88 | ## as function input to plm's summary method (with and without additional arguments): 89 | summary(zz, vcov = vcovSCC) 90 | summary(zz, vcov = function(x) vcovSCC(x, method="arellano", type="HC1")) 91 | ## standard coefficient significance test 92 | library(lmtest) 93 | coeftest(zz) 94 | ## SCC robust significance test, default 95 | coeftest(zz, vcov.=vcovSCC) 96 | ## idem with parameters, pass vcov as a function argument 97 | coeftest(zz, vcov.=function(x) vcovSCC(x, type="HC1", maxlag=4)) 98 | ## joint restriction test 99 | waldtest(zz, update(zz, .~.-log(emp)-unemp), vcov=vcovSCC) 100 | \dontrun{ 101 | ## test of hyp.: 2*log(pc)=log(emp) 102 | library(car) 103 | linearHypothesis(zz, "2*log(pc)=log(emp)", vcov.=vcovSCC) 104 | } 105 | } 106 | \references{ 107 | \insertRef{CRIB:04}{plm} 108 | 109 | \insertRef{DRIS:KRAA:98}{plm} 110 | 111 | \insertRef{HOEC:07}{plm} 112 | 113 | \insertRef{MACK:WHIT:85}{plm} 114 | 115 | \insertRef{ZEIL:04}{plm} 116 | } 117 | \seealso{ 118 | \code{\link[sandwich:vcovHC]{sandwich::vcovHC()}} from the \CRANpkg{sandwich} 119 | package for weighting schemes (\code{type} argument). 120 | } 121 | \author{ 122 | Giovanni Millo, partially ported from Daniel Hoechle's 123 | (2007) Stata code 124 | } 125 | \keyword{regression} 126 | -------------------------------------------------------------------------------- /man/within_intercept.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tool_ranfixef.R 3 | \name{within_intercept} 4 | \alias{within_intercept} 5 | \alias{within_intercept.plm} 6 | \title{Overall Intercept for Within Models Along its Standard Error} 7 | \usage{ 8 | within_intercept(object, ...) 9 | 10 | \method{within_intercept}{plm}(object, vcov = NULL, return.model = FALSE, ...) 11 | } 12 | \arguments{ 13 | \item{object}{object of class \code{plm} which must be a within 14 | model (fixed effects model),} 15 | 16 | \item{\dots}{further arguments (currently none).} 17 | 18 | \item{vcov}{if not \code{NULL} (default), a function to calculate a 19 | user defined variance--covariance matrix (function for robust 20 | vcov), only used if \code{return.model = FALSE},} 21 | 22 | \item{return.model}{a logical to indicate whether only the overall intercept 23 | (\code{FALSE} is default) or a full model object (\code{TRUE}) is to be returned,} 24 | } 25 | \value{ 26 | Depending on argument \code{return.model}: If \code{FALSE} (default), a named 27 | \code{numeric} of length one: The overall intercept for the estimated within model 28 | along attribute "se" which contains the standard error for the intercept. 29 | If \code{return.model = TRUE}, the full model object, a within model with the 30 | overall intercept (NB: the model identifies itself as a pooling model, e.g., 31 | in summary()). 32 | } 33 | \description{ 34 | This function gives an overall intercept for within models and its 35 | accompanying standard error or a within model with the overall intercept 36 | } 37 | \details{ 38 | The (somewhat artificial) intercept for within models (fixed 39 | effects models) was made popular by Stata of StataCorp 40 | \insertCite{@see @GOUL:13}{plm}, EViews of IHS, and gretl 41 | \insertCite{@see @GRETL:2021, p. 200-201, listing 23.1}{plm}, see for 42 | treatment in the literature, 43 | e.g., \insertCite{GREE:12;textual}{plm}, Ch. 11.4.4, p. 364. It can 44 | be considered an overall intercept in the within model framework 45 | and is the weighted mean of fixed effects (see \strong{Examples} for the 46 | relationship). 47 | 48 | \code{within_intercept} estimates a new model which is 49 | computationally more demanding than just taking the weighted 50 | mean. However, with \code{within_intercept} one also gets the 51 | associated standard error and it is possible to get an overall 52 | intercept for two-way fixed effect models. 53 | 54 | Users can set argument \code{vcov} to a function to calculate a 55 | specific (robust) variance--covariance matrix and get the 56 | respective (robust) standard error for the overall intercept, 57 | e.g., the function \code{\link[=vcovHC]{vcovHC()}}, see examples for 58 | usage. Note: The argument \code{vcov} must be a function, not a 59 | matrix, because the model to calculate the overall intercept for 60 | the within model is different from the within model itself. 61 | 62 | If argument \code{return.model = TRUE} is set, the full model object is returned, 63 | while in the default case only the intercept is returned. 64 | } 65 | \examples{ 66 | data("Hedonic", package = "plm") 67 | mod_fe <- plm(mv ~ age + crim, data = Hedonic, index = "townid") 68 | overallint <- within_intercept(mod_fe) 69 | attr(overallint, "se") # standard error 70 | 71 | # overall intercept is the weighted mean of fixed effects in the 72 | # one-way case 73 | weighted.mean(fixef(mod_fe), pdim(mod_fe)$Tint$Ti) 74 | 75 | ### relationship of type="dmean", "level" and within_intercept 76 | ## one-way balanced case 77 | data("Grunfeld", package = "plm") 78 | gi <- plm(inv ~ value + capital, data = Grunfeld, model = "within") 79 | fx_level <- fixef(gi, type = "level") 80 | fx_dmean <- fixef(gi, type = "dmean") 81 | overallint <- within_intercept(gi) 82 | all.equal(overallint + fx_dmean, fx_level, check.attributes = FALSE) # TRUE 83 | ## two-ways unbalanced case 84 | gtw_u <- plm(inv ~ value + capital, data = Grunfeld[-200, ], effect = "twoways") 85 | int_tw_u <- within_intercept(gtw_u) 86 | fx_dmean_tw_i_u <- fixef(gtw_u, type = "dmean", effect = "individual")[index(gtw_u)[[1L]]] 87 | fx_dmean_tw_t_u <- fixef(gtw_u, type = "dmean", effect = "time")[index(gtw_u)[[2L]]] 88 | fx_level_tw_u <- as.numeric(fixef(gtw_u, "twoways", "level")) 89 | fx_level_tw_u2 <- int_tw_u + fx_dmean_tw_i_u + fx_dmean_tw_t_u 90 | all.equal(fx_level_tw_u, fx_level_tw_u2, check.attributes = FALSE) # TRUE 91 | 92 | ## overall intercept with robust standard error 93 | within_intercept(gi, vcov = function(x) vcovHC(x, method="arellano", type="HC0")) 94 | 95 | ## have a model returned 96 | mod_fe_int <- within_intercept(gi, return.model = TRUE) 97 | summary(mod_fe_int) 98 | # replicates Stata's robust standard errors exactly as model is with intercept 99 | summary(mod_fe_int, vcov = function(x) vcovHC(x, type = "sss")) 100 | } 101 | \references{ 102 | \insertAllCited{} 103 | } 104 | \seealso{ 105 | \code{\link[=fixef]{fixef()}} to extract the fixed effects of a within model. 106 | } 107 | \author{ 108 | Kevin Tappe 109 | } 110 | \keyword{attribute} 111 | -------------------------------------------------------------------------------- /tests/test_Evaluation.R: -------------------------------------------------------------------------------- 1 | library(plm) 2 | ## testing whether parameters in variables work (bug by Ulrich Morawtz) 3 | data("Produc", package="plm") 4 | estimation_method <- "within" 5 | estimation_effect <- "individual" 6 | zz <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp, 7 | data=Produc, 8 | index=c("state","year"), 9 | model=estimation_method, 10 | effect=estimation_effect 11 | ) 12 | print(summary(zz)) 13 | --------------------------------------------------------------------------------