the plm package - welcome to the university of...
TRANSCRIPT
The plm PackageMay 15, 2007
Version 0.2-2
Date 2007-05-14
Title Linear models for panel data
Author Yves Croissant <[email protected]>, Giovanni Millo<[email protected]>
Maintainer Yves Croissant <[email protected]>
Depends R (>= 1.8.0), stats, kinship
Suggests Ecdat, lmtest, car
Description A set of estimators and tests for panel data
License GPL version 2 or newer
URL http://www.r-project.org
R topics documented:EmplUK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2FE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Snmesp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4between . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5diff.pserie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6dynformula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7lag.pserie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8mtest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9pFtest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10papply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11pdata.frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12pdim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13pggls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15pgmm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16phtest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1
2 EmplUK
plm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20plmtest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23pooltest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24pread.table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25pvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26pvcm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27pvcovHC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29sargan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31within . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Index 34
EmplUK Employment and Wage in England
Description
a panel of 140 observations from 1976 to 1984
number of observations : 1031
observation : firms
country : United–Kingdom
Usage
data(EmplUK)
Format
A dataframe containing :
firm firm index
year year
emp employment
wage wages
capital capital
output output
Source
Arellano, Manuel & Bond, Stephen (1991), Some Tests of Specification for Panel Data: MonteCarlo Evidence and an Application to Employment Equations, The Review of Economic Studies,vol. 58(2), April 1991, pp.227–297.
FE 3
FE Extract the fixed effects
Description
This function extracts the fixed effects from a plm or a plms object.
Usage
FE(x)## S3 method for class 'plm':FE(x)## S3 method for class 'plms':FE(x)## S3 method for class 'FE':print(x,digits=5,...)## S3 method for class 'FE':summary(object,...)
Arguments
x,object an object of class "plms" or "plm", an object of class FE for the print andthe summary method,
digits digits,
... further arguments.
Details
The element FE of a plm object corresponding to a within model is a numerical vector which lengthis the total number of observations. This function returns a vector which length is the number ofindividuals. The summary method prints the effects in deviation from the overall intercept, thestandard error and the t–values.
Value
An object of class FE. It is a numeric vector containing the fixed effects with two attributes : sewhich contains the standard errors and intercept which is the overall intercept.
Author(s)
Yves Croissant
See Also
plm
4 Snmesp
Examples
library(Ecdat)data(Grunfeld)pdata.frame(Grunfeld,"firm","year")gi <- plm(inv ~ value + capital, data=Grunfeld)FE(gi)FE(gi$within)summary(FE(gi))
Snmesp Employment and Wage in Spain
Description
a panel of 738 observations from 1983 to 1990
number of observations : 5904
observation : firms
country : Spain
Usage
data(Snmesp)
Format
A dataframe containing :
firm firm index
year year
n log of employment
w log of wages
y log of real output
i log of intermediate inputs
k log of real capital stock
f real cash flow
Source
Alonso–Borrego, César and M. Arellano (1999) “Symmetrically Normalized Instrumental-VariableEstimation Using Panel Data”, Journal of Business and Economic Statistics, 17(1), 36–49.
References
Journal of Business Economics and Statistics web site : http://www.amstat.org/publications/jbes/.
between 5
between The between transformation
Description
Computes the between transformation.
Usage
Between(x, ...)## S3 method for class 'pserie':Between(x,effect="individual", ...)## S3 method for class 'matrix':Between(x,cond, ...)## Default S3 method:Between(x,cond, ...)between(x, ...)## S3 method for class 'pserie':between(x,effect="individual", ...)## S3 method for class 'matrix':between(x,cond, ...)## Default S3 method:between(x,cond, ...)
Arguments
x a numeric vector or matrix,
cond a vector containing the conditional variable,
effect the effect for the Between transformation (one of individual and time),
... further arguments.
Value
a vector (or a matrix) of the same length as x containing the between transformation (Between)or of a length equal of the number of modalities of the conditional variable (between).
Author(s)
Yves Croissant
See Also
within and papply.
6 diff.pserie
Examples
library(Ecdat)data(Grunfeld)pdata.frame(Grunfeld,"firm","year")Bi <- Between(Grunfeld$inv)X <- model.matrix(~value+capital-1,Grunfeld)BX <- Between(X,Grunfeld$firm)bi <- between(Grunfeld$inv)bX <- between(X,Grunfeld$firm)# computes the between estimator with the lm commandblm <- lm(between(inv)~between(value)+between(capital),data=Grunfeld)
diff.pserie Difference operator for panel data
Description
Computes the first difference of variables that have a time and an individual dimension.
Usage
diff.pserie(x,lag=0, ...)
Arguments
x a numeric vector for which the difference should be computed,lag the lag for the first difference,... further arguments.
Value
a vector of the same dimension as x containing the lag values. NA values are inserted at the correctpositions.
Author(s)
Yves Croissant
See Also
lag.pserie
Examples
# Anderson and Hsiao estimatorlibrary(Ecdat)data(Grunfeld)pdata.frame(Grunfeld,"firm","year")form <- diff(inv)~diff(inv,1)+diff(value)+diff(capital)hs <- plm(form,data=Grunfeld,instruments=~lag(inv,2),endog=~diff(inv,1),model="pooling")
dynformula 7
dynformula Dynamic formula
Description
A function to create easily formula with lags
Usage
dynformula(formula,lag.form=NULL,diff.form=NULL,log.form=NULL)
Arguments
formula a formula,
lag.form a list containing the lag structure of each variable in the formula,
diff.form a list of logical values indicating whether variables should be differenced,
log.form a list of logical values indicating whether variables should be in logarithms.
Details
lag.form, diff.form and log.form should be lists of length equal to the total number vari-ables. Each element of these lists is :
either a vector of length 2 (c(1,4) means lags 1,2,3 and 4) or a scalar (3 means lags 0,1,2,3 exceptfor the lhs variable for which it is 1,2,3) for lag.form.
logical values for diff.form and log.form.
It can also be an incomplete named list (to apply the transformation for only some variables) witheventually an unnamed element which then is the default value.
Value
an object of class c("dynformula","formula"), which is a formula with four additionalattributes : var, the names of the variables in the formula, lag, diff and log which store theinformation about lags, differences and logs.
Author(s)
Yves Croissant
Examples
# all variables in log, x1, x2 and x3 laged twice, y laged once and x3 differenceddynformula(y~x1+x2+x3,lag.form=list(2,y=1),diff.form=list(x3=TRUE),log.form=TRUE)
8 lag.pserie
lag.pserie Lag operator for panel data
Description
Computes the lag of variables that have a time and an individual dimension.
Usage
lag.pserie(x,k=1,...)
Arguments
x a vector of class pserie,
k the order of the lag to be computed,
... further arguments.
Value
a vector of the same length as x containing the lag values. NA values are inserted at the correctpositions.
Author(s)
Yves Croissant
See Also
diff.pserie
Examples
library(Ecdat)data(Produc)Produc=pdata.frame(Produc,"state","year")lag(Produc$pc)lag(Produc$pc,k=2)
mtest 9
mtest Arellano and Bond test of serial correlation
Description
Test of serial correlation for GMM models
Usage
mtest(object, order=1, vcov=NULL)
Arguments
object an object of class "pgmm",
order the order of the serial correlation (1 or 2),
vcov a matrix of covariance for the coefficients or a function to compute it.
Details
The Arellano and Bond test is a test of correlation based on the residuals of the estimation. Bydefault, the computation is done with the normal covariance matrix of the coefficients. A robustestimator of this covariance matrix can be supplied with the vcov argument.
Value
An object of class "htest".
Author(s)
Yves Croissant
References
Arellano, Manuel & Bond, Stephen (1991), Some Tests of Specification for Panel Data: MonteCarlo Evidence and an Application to Employment Equations, The Review of Economic Studies,vol. 58(2), april 1991, pp.227–297.
Examples
data(EmplUK)pdata.frame(EmplUK,"firm","year")ar <- pgmm(dynformula(log(emp)~log(wage)+log(capital)+log(output),list(2,1,2,2)),EmplUK,
effect="twoways",model="twosteps",gmm.inst=~log(emp),lag.gmm=list(c(2,99)))
mtest(ar,1)mtest(ar,2,pvcovHC)
10 pFtest
pFtest F test for effects
Description
Test of individuals and/or time effects based on the comparison of the within and the poolingmodel.
Usage
pFtest(x, ...)## S3 method for class 'plm':pFtest(x,z,data=NULL, ...)## S3 method for class 'plms':pFtest(x,...)
Arguments
x an object of class "plms" or "plm",
z an object of class "plm",
data data,
... further arguments.
Details
The argument of this function is whether a plms object or two plm objects, the first being a withinmodel, the second a pooling model. The effects tested are whether individual, time or twowayseffects depending on the effects introduced in the model.
Value
An object of class "htest".
Author(s)
Yves Croissant
See Also
plmtest for Lagrange multipliers tests of individuals and/or time effects.
papply 11
Examples
library(Ecdat)data(Grunfeld)Grunfeld <-pdata.frame(Grunfeld,"firm","year")gi <- plm(inv ~ value + capital, data=Grunfeld)gt <- plm(inv ~ value + capital, data=Grunfeld,effect="time")gd <- plm(inv ~ value + capital, data=Grunfeld,effect="twoways")pFtest(gi)pFtest(gi$within,gi$pooling)pFtest(gt)pFtest(gd)
papply Conditional operation for panel data
Description
Apply an operation to a vector or a matrix for panel data.
Usage
papply(x, ...)## S3 method for class 'pserie':papply(x,func,effect="individual", ...)## S3 method for class 'matrix':papply(x,func,cond, ...)## Default S3 method:papply(x,func,cond, ...)
Arguments
x a numeric vector or matrix,
func the function to apply to x,
cond a vector containing the conditional variable,
effect the effect for the papply transformation (one of individual or time),
... further arguments.
Value
a vector (or a matrix) of the same dimension as the first argument.
Author(s)
Yves Croissant
12 pdata.frame
Examples
library(Ecdat)data(Grunfeld)pdata.frame(Grunfeld,"firm","year")papply(Grunfeld$inv,mean)X <- model.matrix(~value+capital-1,Grunfeld)papply(X,mean,Grunfeld$firm)
pdata.frame Data frame for panel data
Description
a data.frame with further attributes useful for panel data
Usage
pdata.frame(x,id,time=NULL,name=NULL)## S3 method for class 'pdata.frame':summary(object,...)## S3 method for class 'summary.pdata.frame':print(x,...)
Arguments
x a data.frame (a pdata.frame for the print and summary methods),object a pdata.frame object,id the individual index,time the time index,name the name of the pdata.frame (the name of x if NULL),... further arguments.
Details
id and time can be the names of the indexes contained in the data.frame if any. time maybe omitted, in this case a new variable called "time" is added to the data.frame. For balancedpanels, the argument id can be an integer. In this case, two new variables, "time" and "id" areadded to the data.frame.
pdata.frame calls pdim to check for the individual and time dimensions of the panel and pvarto check for the individual and time variation of each variable.
All elements of a pdata.frame are of class pserie and have an attribute data which is thename of the pdata.frame.
The print method is inherited from data.frame. A summary method is provided which addto the summary.data.frame method informations about the structure of the panel.
A as.data.framemethod is also provided to coerce a pdata.frame to an ordinary data.frame.Finally, a pfix function is available to edit a pdata.frame. It mimics the behavior of fix(which is not a generic function). Only editing is possible, not modification.
pdim 13
Value
This function returns internally an object of class c("pdata.frame","data.frame"), whichis a data.frame with three additional attributes :
indexes a list containing the names of the individual (id) and time (time) index vari-ables,
pdim a list containing the dimension of the pdata.frame (see pdim),
pvar a list of two logical vectors indicating whether each variable varies across indi-viduals (id.var) and across time periods (time.var) (see pvar).
Author(s)
Yves Croissant
See Also
pdim, pvar, pread.table.
Examples
library(Ecdat)
#There are 595 individuals
data(Wages)pdata.frame(Wages,595)
# Gasoline contains two variables which are individual and time indexes# The pdata.frame is called gasdata(Gasoline)pdata.frame(Gasoline,"country","year",name="gas")summary(gas)
# Hedonic is an unbalanced panel, townid is the individual indexdata(Hedonic)pdata.frame(Hedonic,"townid")
pdim Check for the dimensions of the panel
Description
This function checks the number of individuals and time observations in the panel and whether it isbalanced or not.
14 pdim
Usage
pdim(x,...)## S3 method for class 'pdata.frame':pdim(x,...)## S3 method for class 'data.frame':pdim(x,id,time,...)
Arguments
x a data.frame or a pdata.frame,
id the individual index,
time the time index,
... further arguments.
Details
pdim is called by pdata.frame and by plm if there are some missing values.
Value
an object of class pdim containing the following elements :
nT a list containing n, the number of individuals, T, the number of time observa-tions, N the total number of observations,
TinT a list containing two vectors : Ti gives the number of observations for eachindividuals and nt gives the number of individuals observed for each period,
balanced a logical value : TRUE for a balanced panel, FALSE for an unbalanced panel,
panel.names a list of character vectors : id.names contains the names of each individualand time.names contains the names of each period.
Author(s)
Yves Croissant
See Also
pdata.frame and plm
Examples
library(Ecdat)data(Produc)pdim(Produc,"state","year")
pggls 15
pggls General FGLS Estimators
Description
General FGLS estimators for panel data (balanced or unbalanced)
Usage
pggls(formula,data,effect="individual",model, ...)## S3 method for class 'pggls':summary(object, ...)## S3 method for class 'summary.pggls':print(x,digits=5,length.line=70, ...)
Arguments
formula a symbolic description for the model to be estimated,
object,x an object of class pggls,
data the data, must be an object of class pdata.frame and is mandatory,
effect the effects introduced in the model, one of "individual" or "time",
model one of "within" or "random",
digits digits,
length.line the maximum length of the lines in the print output,
... further arguments.
Details
pggls is a function for the estimation of linear panel models by general feasible generalized leastsquares, either with or without fixed effects. General FGLS is based on a two-step estimation pro-cess: first a model is estimated by OLS (random) or fixed effects (within), then its residualsare used to estimate an error covariance matrix for use in a feasible-GLS analysis. This frame-work allows the error covariance structure inside every group (if effect="individual", elsesymmetric) of observations to be fully unrestricted and is therefore robust against any type of in-tragroup heteroskedasticity and serial correlation. This structure, by converse, is assumed identicalacross groups and thus general FGLS estimation is inefficient under groupwise heteroskedasticity.Care shall also be taken that this method requires estimation of T(T+1)/2 variance parameters, thusefficiency requires N > >T (if effect="individual", else the opposite).
Value
an object of class c("pggls","panelmodel") containing :
coefficients the vector of coefficients,
residuals the vector of residuals,
16 pgmm
fitted.valuesthe vector of fitted.values,
vcov the covariance matrix of the coefficients,
df.residual degrees of freedom of the residuals,
model a data.frame containing the variables used for the estimation,
call the call,
sigma the estimated intragroup (or cross-sectional, if effect="time") covarianceof errors,
Author(s)
Giovanni Millo
References
Kiefer, N. M. (1980), Estimation of Fixed Effects Models for Time Series of Cross-Sections withArbitrary Intertemporal Covariance, Journal of Econometrics, 14, 195–202.
Wooldridge J. M. (2003), Econometric Analysis of Cross Section and Panel Data, MIT Press
See Also
pdata.frame for the creation of a pdata.frame.
Examples
library(Ecdat)data(Produc)Produc <-pdata.frame(Produc,"state","year")zz <- pggls(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp,data=Produc,model="random")summary(zz)
pgmm General method of moments estimator for panel data
Description
General method of moments estimator for static or dynamic models with panel data.
Usage
pgmm(formula,data,effect="individual",model="twosteps",instruments=NULL,gmm.inst,lag.gmm,transformation="d",fsm=NULL,...)## S3 method for class 'pgmm':summary(object,robust, ...)## S3 method for class 'summary.pgmm':print(x,digits=5,length.line=70, ...)
pgmm 17
Arguments
formula a symbolic description for the model to be estimated. Should be an object ofclass dynformula
object,x an object of class pgmm,
data the data, must be an object of class pdata.frame and is mandatory,
effect the effects introduced in the model, one of "individual" or "twoways",
model one of "onestep" or "twosteps",
instruments a one side formula containing the normal instruments,
gmm.inst a one side formula containing the GMM instruments,
lag.gmm a list containing the lags to use for each GMM instrument, or a list of two namedlists ("d" for difference and "l" for level) in case of “system GMM”,
transformationthe kind of transformation to apply to the model : either "d" (the default value)for the “difference GMM” model or "ld" for the “system GMM”,
fsm the matrix for the one step estimator : one of "I" (identity matrix) or "G"(= D′D where D is the first difference operator) if transformation="d",one of "GI" or "full" if transformation="ld",
digits digits,
length.line the maximum length of the lines in the print output,
robust if TRUE, robust inference is performed in the summary,
... further arguments.
Details
pgmm estimate a model for panel data with the general method of moments estimator. The de-scription of the model to estimate is provided with a dynformula. The GMM instruments areprovided by filling the pgmm.inst argument with a one side formula. By default, all the variablesof the model which are not used as GMM instruments are used as normal instruments with thesame lag structure as the one specified in the dynformula, but the user may also specified oneside formula to indicate expicitly the variables to use as normal instruments. The lags used for theGMM instruments are indicated with the lag.gmm argument. For each instrument, it is either avector of length 2 (c(99,3) indicates to use all the lags available up to t-3), or a scalar (2 indicates touse the lags 0, 1 and 2). If a single vector (or scalar) is written, then this lag structure is replicatedfor all GMM instruments. Otherwise, lag.gmm should be a list of length equal to the number ofGMM instruments. transformation indicates how the model should be transformed for theestimation. "d" gives the “difference GMM” model (see Arellano and Bond (1991)), "ld" the“system GMM” model (see Blundell and Bond (1998)).
pgmm is an attempt to adapt GMM estimators availaible with the PDP library for GAUSS (seeArellano and Bound 1998) and OX (see Doornik, Arelanno and Bond 2006) and with the xtabound2library for STATA (see Roodman 2006).
18 pgmm
Value
an object of class c("pgmm","panelmodel"), which has the following elements :
coefficients the vector (or the list for fixed effects) of coefficients,
residuals the vector of residuals,fitted.values
the vector of fitted.values,
vcov the covariance matrix of the coefficients,
df.residual degrees of freedom of the residuals,
model a list containing the variables used for the estimation for each individual,
W a list containing the instruments for each individual (two lists in case of “sys–GMM”),
K a list containing K the number of explanatory variables, Ky the number of lagsof the dependent variable and Kt the number of time dummies,
A1 the weighting matrix for the one–step estimator,
A2 the weighting matrix for the two–steps estimator,
call the call.
It has print, summary and print.summary methods.
Author(s)
Yves Croissant
References
Arellano, Manuel & Bond, Stephen (1991), Some Tests of Specification for Panel Data: MonteCarlo Evidence and an Application to Employment Equations, The Review of Economic Studies,vol. 58(2), april 1991, pp.227–297.
Arellano, Manuel & Bond, Stephen (1998), Dynamic Panel Data Estimation Using DPD89 forGAUSS : a Guide for Users.
Blundell, Richard and Stephen Bond (1998), Initial Conditions and Moment Restrictions in Dy-namic Panel Data Models, Journal of Econometrics, vol. 87, pp.115–143.
Doornik, Jurgen, Arellano, Manuel and Stephen Bond (2006), Panel Data Estimation using DPDfor Ox.
Roodman, David (2006), How to do xtabound2 : an Introduction to “difference” and “system”GMM in Stata, working paper no 103, Center for Global Development.
See Also
dynformula for dynamic formulas, sargan for Sargan tests and mtest for Arellano and Bond’s tests of mulicolinearity
phtest 19
Examples
data(EmplUK)pdata.frame(EmplUK,"firm","year")
## Arelanno Bound 91 table 4bz1 <- pgmm(dynformula(log(emp)~log(wage)+log(capital)+log(output),list(2,1,0,1)),EmplUK,
effect="twoways",model="twosteps",gmm.inst=~log(emp),lag.gmm=list(c(2,99)))
## BLUNDEL AND BOND TAB4 cf DPD for OX p12 col 4
z2 <- pgmm(dynformula(log(emp)~log(wage)+log(capital),list(1,1,1)),EmplUK,effect="twoways",model="onestep",gmm.inst=~log(emp)+log(wage)+log(capital),lag.gmm=c(2,99),transformation="ld")
summary(z2,robust=TRUE)
phtest Hausman test for panel models
Description
Specification test for panel models.
Usage
phtest(x, ...)## S3 method for class 'panelmodel':phtest(x,x2,data=NULL, ...)## S3 method for class 'plms':phtest(x,...)
Arguments
x an object of class "plms" or "panelmodel",
x2 an object of class "panelmodel",
data
... further arguments.
Details
The Hausman test is based on the difference of the vectors of coefficients of two different models.If the argument of phtest is an object of class plms, the Hausman test compares the within andthe random effects model.
20 plm
Value
An object of class "htest".
Author(s)
Yves Croissant
References
Hausman, J.A. (1978), Specification tests in econometrics, Econometrica, 46, pp.1251–1271.
Examples
library(Ecdat)data(Gasoline)Gasoline <- pdata.frame(Gasoline,"country","year")form <- lgaspcar~lincomep+lrpmg+lcarpcapgas <- plm(form,data=Gasoline)phtest(gas)phtest(gas$between, gas$random)
plm Panel Data Estimators
Description
Linear models for panel data estimated using the lm function to transformed data.
Usage
plm(formula,data,effect="individual",model=NULL,instruments=NULL,endog=NULL,random.method="swar",inst.method="bvk", ...)## S3 method for class 'plm':summary(object, ...)## S3 method for class 'plms':print(x,digits=5, ...)## S3 method for class 'plms':summary(object, ...)## S3 method for class 'summary.plm':print(x,digits=5,length.line=70, ...)## S3 method for class 'summary.plms':print(x,digits=5,length.line=70, ...)
plm 21
Arguments
formula a symbolic description for the model to be estimated,
object,x an object of class plm or plms,
data the data, must be an object of class pdata.frame and is mandatory,
effect the effects introduced in the model, one of "individual", "time" or "twoways",
model one of "pooling", "within", "between", "random", "nopool" and"ht" : plm returns the model specified or, if NULL, a list containing fourmodels ("pooling", "within", "between" and "random"),
instruments a one side formula containing instrumental variables,
endog a one side formula containing endogenous variables,random.method
method of estimation for the variance components in the random effect model,one of "swar" (the default value), "amemiya", "walhus" and "nerlove",
inst.method the instrumental variable transformation : one of "bvk" and "baltagi",
digits digits,
length.line the maximum length of the lines in the print output,
... further arguments.
Details
plm is a general function for the estimation of linear panel models. It offers limited support forunbalanced panels and estimation of two-ways effects models.
For random effect models, 4 estimators of the transformation parameter are available : swar(Swamy and Arora), amemiya, walhus (Wallace and Hussain) and nerlove.
Instrumental variables estimation is obtained using the instruments and/or endog arguments.If for example, the model is y~x1+x2+x3, x1, x2 are endogenous and z1, z2 are external instru-ments, the model can be estimated with : instruments=~x3+z1+z2, or instruments=~z1+z2,endog=~x1+x2.The four models are estimated using Balestra and Varadharajan–Krishnakumar’s method if inst.method=bvkor Baltagi’s method if inst.method="baltagi".
The Hausman and Taylor estimator is computed if model="ht".
Value
Whether : an object of class "plms", which is a list of the following models : pooling,between (between.id and between.time if method="twoways"), within and randomwhich are all of class "plm",
an object of class c("plm","panelmodel") if the argument model is filled.
A "plm" object has the following elements :
coefficients the vector of coefficients,
residuals the vector of residuals,fitted.values
the vector of fitted.values,
22 plm
vcov the covariance matrix of the coefficients,
df.residual degrees of freedom of the residuals,
model a data.frame containing the variables used for the estimation,
call the call,
FE the fixed effects (only for within models),
alpha the overall intercept (only for within models),
theta the parameter of transformation (only for random effect models),
sigma2 the variance of the different elements of the error (only for random effect mod-els),
It has print, summary and print.summary methods.
A specific summary method is provided for objects of class "plms", which returns an object ofclass summary.plms and prints a table of the coefficients of the within and random models andtheir standard errors.
Author(s)
Yves Croissant
References
Amemiyia, T. (1971), The estimation of the variances in a variance–components model, Interna-tional Economic Review, 12, pp.1–13.
Balestra, P. and J. Varadharajan–Krishnakumar (1987), Full information estimations of a system ofsimultaneous equations with error components structure, Econometric Theory, 3, pp.223–246.
Baltagi, B.H. (1981), Simultaneous equations with error components, Journal of econometrics, 17,pp.21–49.
Baltagi, B.H. (2001) Econometric Analysis of Panel Data. John Wiley and sons. ltd.
Hausman, J.A. and W.E. Taylor (1981), Panel data and unobservable individual effects, Economet-rica, 49, pp.1377–1398.
Nerlove, M. (1971), Further evidence on the estimation of dynamic economic relations from atime–series of cross–sections, Econometrica, 39, pp.359–382.
Swamy, P.A.V.B. and S.S. Arora (1972), The exact finite sample properties of the estimators ofcoefficients in the error components regression models, Econometrica, 40, pp.261–275.
Wallace, T.D. and A. Hussain (1969), The use of error components models in combining crosssection with time series data, Econometrica, 37(1), pp.55–72.
See Also
pdata.frame for the creation of a pdata.frame.
plmtest 23
Examples
library(Ecdat)data(Produc)Produc <-pdata.frame(Produc,"state","year")zz <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp,data=Produc)summary(zz$random)
plmtest Lagrance mulitplier tests for panel models
Description
Test of individual and/or time effect for panel models.
Usage
plmtest(x, ...)## S3 method for class 'plm':plmtest(x,effect="id",type="bp", ...)## S3 method for class 'plms':plmtest(x,effect="id",type="bp", ...)
Arguments
x an object of class plm or plms,
effect a character string indicating which effects are tested : individual effects ("id"),time effects ("time") or both ("twoways"),
type a character string indicating the test to be computed : "bp" for Breush-Pagan(1980), "ghm" for Gourieroux, Holly and Monfort (1982), "honda" for Honda(1985) or "kw" for King and Wu (1997),
... further arguments.
Details
These Lagrange multiplier tests use only the residuals of the pooling model. The main argument ofthis function may be whether a pooling model of class plm or an object of class plms.
Value
An object of class "htest".
Author(s)
Yves Croissant
24 pooltest
References
Breusch, T.S. and A.R. Pagan (1980), The Lagrange multiplier test and its applications to modelspecification in econometrics, Review of Economic Studies, 47, pp.239–253.
Gourieroux, C., A. Holly and A. Monfort (1982), Likelihood ratio test, Wald test, and Kuhn–Tuckertest in linear models with inequality constraints on the regression parameters, Econometrica, 50,pp.63–80.
Honda, Y. (1985), Testing the error components model with non–normal disturbances, Review ofEconomic Studies, 52, pp.681–690.
King, M.L. and P.X. Wu (1997), Locally optimal one–sided tests for multiparameter hypotheses,Econometric Reviews, 33, pp.523–529.
See Also
pFtest for individual and/or time effects tests based on the within model.
Examples
library(Ecdat)data(Grunfeld)Grunfeld <-pdata.frame(Grunfeld,"firm","year")g <- plm(inv ~ value + capital, data=Grunfeld)plmtest(g)plmtest(g,effect="time")plmtest(g,type="honda")plmtest(g,type="ghm",effect="twoways")plmtest(g,type="kw",effect="twoways")
pooltest Test of poolability
Description
A Chow test for the poolability of the data.
Usage
pooltest(x,...)## S3 method for class 'plms':pooltest(x,nopool,effect=FALSE,...)## S3 method for class 'plm':pooltest(x,nopool,...)
pread.table 25
Arguments
x an object of class "plms" or "plm",
nopool an object of class "pvcm" obtained with effect="within",
effect if x is a plms and effect=TRUE the nopool model is compared to thewithin model, if FALSE to the pooling model.
... further arguments.
Details
pooltest is a F test of stability (or Chow test) for the coefficients of a panel model.
Value
An object of class "htest".
Author(s)
Yves Croissant
Examples
library(Ecdat)data(Gasoline)Gasoline <- pdata.frame(Gasoline,"country","year")form <- lgaspcar~lincomep+lrpmg+lcarpcapgas <- plm(form,data=Gasoline)gasnp <- pvcm(form,data=Gasoline,model="within")pooltest(gas,gasnp)pooltest(gas,gasnp,effect=TRUE)
pread.table Read panel data from text file
Description
Create a pdata.frame directly by reading a text file.
Usage
pread.table(file,id,time=NULL,name=NULL,...)
26 pvar
Arguments
file a text file,
id the name of the individual index,
time the name of the time index,
name the name of the pdata.frame. If missing, the name of the pdata.frameis the name of the file, without the path and the extension,
... further arguments passed to read.table.
Value
a pdata.frame object
Author(s)
Yves Croissant
See Also
pdata.frame
pvar Check whether variables of a panel have individual and time varia-tions
Description
This function checks for each variable of a panel if it has an individual and a time variation.
Usage
pvar(x, ...)## S3 method for class 'pdata.frame':pvar(x, ...)## S3 method for class 'data.frame':pvar(x,id,time, ...)## S3 method for class 'matrix':pvar(x,id,time, ...)
Arguments
x a data.frame, a pdata.frame or a matrix object,
id a vector containing the individual index,
time a vector containing the time index,
... further arguments.
pvcm 27
Details
pvar is called by pdata.frame and by plm in there are some missing values.
Value
an object of class pvar containing the following elements :
id.var a logical vector with TRUE values if the variable has individual variation, FALSEotherwise,
time.var a logical vector with TRUE values if the variable has time variation, FALSEotherwise,
Author(s)
Yves Croissant
See Also
pdata.frame and plm.
Examples
library(Ecdat)data(Produc)pvar(Produc,"state","year")
pvcm Variable coefficients models for panel data
Description
Estimators for random and fixed effect models with variable coefficients.
Usage
pvcm(formula,data,effect="individual",model,...)## S3 method for class 'pvcm':summary(object, ...)## S3 method for class 'summary.pvcm':print(x,digits=5,length.line=70, ...)
28 pvcm
Arguments
formula a symbolic description for the model to be estimated,object,x an object of class pvcm,data the data, must be an object of class pdata.frame and is mandatory,effect the effects introduced in the model, one of "individual" or "time",model one of "within" or "random",digits digits,length.line the maximum length of the lines in the print output,... further arguments.
Details
The pvcm function enables the estimation of variable coefficients models. Time or individualeffects are introduced if effect is fixed to "time" or "individual" (the default value).
Coefficients are assumed to be fixed if model="within" and random if model="random".In the first case, a different model is estimated for each individual (or time period). In the secondcase, the SWAMY (1970) model is estimated. It is a generalized least squares model which use theresults of the previous model.
Value
an object of class c("pvcm","panelmodel"), which has the following elements :
coefficients the vector (or the list for fixed effects) of coefficients,residuals the vector of residuals,fitted.values
the vector of fitted.values,vcov the covariance matrix of the coefficients,df.residual degrees of freedom of the residuals,model a data.frame containing the variables used for the estimation,call the call,Delta the estimation of the covariance matrix of the coefficients (random effect models
only),std.error the standard errors for all the coefficients for each individual (within models
only),
pvcm objects have print, summary and print.summary methods.
Author(s)
Yves Croissant
References
Swamy, P.A.V.B. (1970), Efficient Inference in a Random Coefficient Regression Model, Econo-metrica, 38(2), pp.311–323.
pvcovHC 29
Examples
library(Ecdat)data(Produc)pdata.frame(Produc,"state","year","pprod")zw <- pvcm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp,data=pprod,model="within")zr <- pvcm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp,data=pprod,model="random")
pvcovHC Robust covariance matrix estimators
Description
Robust covariance matrix estimators à la White for panel models.
Usage
pvcovHC(x,...)## S3 method for class 'panelmodel':pvcovHC(x,type="white1",weights="HC0", ...)## S3 method for class 'pgmm':pvcovHC(x,...)
Arguments
x an object of class "panelmodel" which should be the result of a random or awithin model or a model of class pgmm,
type one of "white1","white2","arellano",
weights one of "HC0","HC1","HC2","HC3","HC4",
... further arguments.
Details
pvcovHC is a function for estimating a robust covariance matrix of parameters for a fixed effectsor random effects panel model according to the White method (White 1980, 1984; Arellano 1987).
All types assume no intragroup correlation between errors and allow for heteroskedasticity acrossgroups. As for the error covariance matrix of every single group of observations, "white1" allowsfor general heteroskedasticity but no serial correlation; "white2" is "white1" restricted to acommon variance inside every group (see Greene (2003), 13.7.1-2 and Wooldridge (2003), 10.7.2);"arellano" (see ibid. and the original ref. Arellano (1987)) allows a fully general structure w.r.t.heteroskedasticity and serial correlation.
Weighting schemes are analogous to those in vcovHC in package sandwich and are justifiedtheoretically (although in the context of the standard linear model) by MacKinnon and White (1985)and Cribari-Neto (2004) (see Zeileis, 2004).
The main use of pvcovHC is to be an argument to other functions, e.g. for Wald-type testing:as vcov to coeftest(), waldtest() and other methods in the lmtest package; and as
30 pvcovHC
vcov to linear.hypothesis() in the car package (see the examples). Notice that the vcovargument may be supplied a function (which is the safest) or a matrix (see Zeileis (2004), 4.1-2 andexamples below).
A special procedure, proposed by Windmeijer (2005) for pgmm objects.
Value
An object of class "matrix" containing the estimate of the asymptotic covariance matrix of coef-ficients.
Author(s)
Giovanni Millo & Yves Croissant
References
Arellano M. (1987), Computing robust standard errors for within group estimators, Oxford bulletinof Economics and Statistics, 49, 431–434.
Cribari-Neto F. (2004), Asymptotic inference under heteroskedasticity of unknown form. Compu-tational Statistics & Data Analysis 45, 215–233.
Greene W. H. (1993), Econometric Analysis, 2nd ed. Macmillan Publishing Company, New York.
MacKinnon J. G., White H. (1985), Some heteroskedasticity-consistent covariance matrix estima-tors with improved finite sample properties. Journal of Econometrics 29, 305–325.
Weidmeijer, F. (2005), A finite sample correction for the variance of linear efficicent two–stepGMM estimators, Journal of Econometrics, 126, pp.25–51.
White H. (1980), Asymptotic Theory for Econometricians, Ch. 6, Academic Press, Orlando (FL).
White H. (1984), A heteroskedasticity-consistent covariance matrix and a direct test for heteroskedas-ticity. Econometrica 48, 817–838.
Wooldridge J. M. (2003), Econometric Analysis of Cross Section and Panel Data, MIT Press
Zeileis A. (2004), Econometric Computing with HC and HAC Covariance Matrix Estimators. Jour-nal of Statistical Software, 11(10), 1–17. URL http://http://www.jstatsoft.org/v11/i10/.
Examples
library(lmtest)library(car)library(Ecdat)library(plm)data(Produc)Produc <-pdata.frame(Produc,"state","year")zz <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp,data=Produc,model="random")## standard coefficient significance testcoeftest(zz)## robust significance testcoeftest(zz, vcov=pvcovHC)## idem with parameters, pass vcov as a function argumentcoeftest(zz, vcov=function(x) pvcovHC(x, type="arellano", weights="HC1"))
sargan 31
## idem with parameters, pass vcov as a matrix argumentcoeftest(zz, vcov=pvcovHC(zz, type="arellano", weights="HC1"))## joint restriction testwaldtest(zz, update(zz, .~.-log(emp)-unemp), vcov=pvcovHC)## test of hyp.: 2*log(pc)=log(emp)linear.hypothesis(zz, "2*log(pc)=log(emp)", vcov=pvcovHC)
## Robust inference for GMM modelsdata(EmplUK)pdata.frame(EmplUK,"firm","year")ar <- pgmm(dynformula(log(emp)~log(wage)+log(capital)+log(output),list(2,1,2,2)),EmplUK,
effect="twoways",model="twosteps",gmm.inst=~log(emp),lag.gmm=list(c(2,99)))
rv <- pvcovHC(ar)mtest(ar,order=2,vcov=rv)
sargan Hansen–Sargan test of overidentifying restrictions
Description
A test of overidentifying restrictions for GMM models
Usage
sargan(object)
Arguments
object an object of class "pgmm".
Details
The Hansen–Sargan test calculate the quadratic form of the moment restrictions that is minimizedwhile computing the GMM estimator. It follows asymptotically a chi square with a number ofdegrees of freedom equal to the difference of the number of moment conditions and the number ofcoefficients.
Value
An object of class "htest".
Author(s)
Yves Croissant
32 within
References
Hansen, L.P. (1982), Large Sample Properties of Generalized Methods of Moments Estimators,Econometrica, 50, 1029–54.
Sargan, J.D. (1958), The Estimation of Economic Relationships using Instrumental Variables, Econo-metrica, 26, pp.393–415.
Examples
data(EmplUK)pdata.frame(EmplUK,"firm","year")ar <- pgmm(dynformula(log(emp)~log(wage)+log(capital)+log(output),list(2,1,2,2)),EmplUK,
effect="twoways",model="twosteps",gmm.inst=~log(emp),lag.gmm=list(c(2,99)))
sargan(ar)
within The within transformation
Description
Computes the within transformation
Usage
within(x, ...)## S3 method for class 'pserie':within(x,effect="individual", ...)## S3 method for class 'matrix':within(x,cond, ...)
Arguments
x a numeric vector or a matrix,
cond a vector containing the conditional variable,
effect the effect for the within transformation (one of individual, time and twoways),
... further arguments.
Value
a vector of the same length as x containing the within transformation.
Author(s)
Yves Croissant
within 33
See Also
between and papply
Examples
library(Ecdat)data(Grunfeld)pdata.frame(Grunfeld,"firm","year")wi <- within(Grunfeld$inv)w2 <- within(Grunfeld$inv,effect="twoways")X <- model.matrix(~value+capital-1,Grunfeld)Xt <- within(X,Grunfeld$firm)
Index
∗Topic arithbetween, 4diff.pserie, 5lag.pserie, 7papply, 10within, 31
∗Topic attributeFE, 2pdata.frame, 11pdim, 12pread.table, 24pvar, 25
∗Topic datasetsEmplUK, 1Snmesp, 3
∗Topic htestmtest, 8pFtest, 9phtest, 18plmtest, 22pooltest, 23sargan, 30
∗Topic regressiondynformula, 6pggls, 14pgmm, 15plm, 19pvcm, 26pvcovHC, 28
as.data.frame.pdata.frame(pdata.frame), 11
Between (between), 4between, 4, 32Between.default (between), 4between.default (between), 4Between.matrix (between), 4between.matrix (between), 4Between.pserie (between), 4
between.pserie (between), 4
diff (diff.pserie), 5diff.pserie, 5, 7dynformula, 6, 16, 17
EmplUK, 1
FE, 2
lag (lag.pserie), 7lag.pserie, 6, 7
mtest, 8
papply, 5, 10, 32pdata.frame, 11, 13, 15, 21, 25, 26pdim, 12, 12pdim.pdata.frame (pdim), 12pfix (pdata.frame), 11pFtest, 9, 23pggls, 14pgmm, 15phtest, 18plm, 3, 13, 19, 26plmtest, 10, 22pooltest, 23pread.table, 12, 24print.FE (FE), 2print.panelmodel (plm), 19print.pdim (pdim), 12print.plms (plm), 19print.pvar (pvar), 25print.summary.pdata.frame
(pdata.frame), 11print.summary.pggls (pggls), 14print.summary.pgmm (pgmm), 15print.summary.plm (plm), 19print.summary.plms (plm), 19print.summary.pvcm (pvcm), 26pvar, 12, 25
34