fastplm: Solve Fixed Effect Model

View source: R/fastplm.R

fastplmR Documentation

Solve Fixed Effect Model

Description

fastplm solves a fixed effects model or a 2SLS regression with fixed effects.

Usage

fastplm(data = NULL, formula = NULL,
			   index = NULL, y = NULL, 
			   x = NULL, z = NULL,
			   ind = NULL, sfe = NULL,
			   cfe = NULL, PCA = TRUE,
			   sp = NULL, knots = NULL,
			   degree = 3, se = 1,
			   vce = "robust", cluster = NULL,
			   wild = TRUE, refinement = FALSE,
			   test_x = NULL, parallel = TRUE,
			   nboots = 200, seed = NULL,
			   core.num = 1, drop.singletons = TRUE,
			   bootcluster = NULL, iv.test = TRUE,
			   first = FALSE, orthog = NULL,
			   endog = NULL)

Arguments

data

An object of class "dataframe" or "matrix". If both formula and y are omitted, the first column of data will be regarded as the vector of outcome variable and other columns will be regarded as regressors. If both data and y present, data is omitted.

formula

An object of class "formula": a symbolic description of the model to be fitted. If it has the form "Y~1", the function merely estimates fixed effects.

index

A string vector specifying the indicators. Omissible if formula is omitted.

y

The Y matrix. Omissible if formula is provided.

x

The X matrix. Omissible if formula is provided. If X are not provided and formula is absent, the model is still valid. In such case, the function merely estimates fixed effects.

z

A string vector of the names of all exogenous variables (both of excluded IVs and included IVs) if formula is present. It can also be a matrix of all exogenous variables if formula is absent.

ind

A matrix where each row corresponds to the row (observation) in the X-Y dataset and each column represents an effect. The entry of row X of effect Y represents the group in Y that X belongs to. Groups can be specified by either numbers or strings, i.e. the input matrix can be of mode numeric or character.

sfe

A vector index of simple (additive) fixed effects. Each can be specified either by effect name or position as in index or by the position in the indicator matrix ind. If omitted, sfe will be the collection of all effects in index or inds.

cfe

A list index of complex fixed effects.

Specifically, an complex fixed effect is a generalized fixed effect. It consists a pair of two effects, (I, E), interacting with each other. "I" stands for influence, whose level has an observed vector weight. "E" stands for effect, whose level has an unobserved vector coefficient to estimate. For each observation, the effect of (I, E) is the dot product of the weight of the row's level for "I" and the coefficient of the row's level for "E".

Each element is a vector whose length is 2. The 1st item of each element is the index of effect and the 2nd item is the index of influence. For index, see sfe.

If omitted, complex fixed effects will not be estimated.

PCA

A logical flag indicating whether to perform principal components analysis for influence in complex fixed effects (see cfe).

sp

A character value or a numeric vector specifying the variable for fitting a b-spline curve.

knots

A numeirc value specifying the knots point for sp. If left blank, a polynomial curve will be fitted by default.

degree

A positive integer speficying the order of the spline curve. Default value is degree = 3 for a cubic curve.

se

A logical flag indicating whether uncertainty estimates of covariates will be produced. For 2sls regressions, all diagnostic tests will not be conducted if se = FALSE.

vce

A character value indicating type for variance estimator. Choose from: "standard" for standard ols standard errors, "robust" for the Huber White robust standard errors (default value), "clustered" (or "cl") for clustered standard errors, "jackknife" for jackknife standard errors, and "bootstrap" (or "boot") for bootstrapped standard errors.

cluster

A character value of the clustered variable(s) in the data frame if formula is provided or a matrix object of the clustered variable(s) for clustered standard error or clustered bootstrap. Two-way clustering is also supported.

wild

A logical flag specifies if wild bootstrap will be performed to obtain uncertainty estimates. Omissible if se = FALSE. Default to TRUE for computational efficiency.

refinement

A logical flag specifies if bootstrap refinement will be performed to obtain uncertainty estimates. Omissible if se = FALSE. Default to FALSE.

test_x

A character specifies the variable of interest for wild bootstrap refinement. Omissible if refinement = FALSE or wild = FALSE. When wild = TRUE, if test_x = NULL, an unrestricted wild bootstrap will be conducted, otherwise, a restricted wild bootstrap will be performed. Default to NULL.

parallel

A logical flag indicating whether to perform parallel computing for the bootstrap procedure. Default to TRUE.

nboots

An integer specifying the number of bootstrap runs. Omissible if se = FALSE.

seed

An integer that sets the seed in random number generation. Omissible if se = FALSE.

core.num

The number of cores that will be used for computation. Default is one. Larger number of cores can improve the speed moderately.

drop.singletons

A logical flag indicating whether to drop singletons(groups with only one observation). Default to TRUE. The program can report the number of singletons it detects and return a vector drop.index noting the indices of dropped observations.

bootcluster

A character value specifying the level of bootstrap in two-way clustered bootstrap refinement. Must be one of the names of cluster.

iv.test

A logical flag indicating whether to conduct diagnostic tests for 2SLS regressions, including weak IV tests, exogeneity tests, and endogeneity tests. Default to TRUE. Omissible if se=FALSE or vce="bootsrap" or "jackknife".

first

A logical flag indicating whether to compute partial F statistics, Sanderson-Windmeijer (SW) F statistics and Angrist and Pischke (AP) F statistics for first stage regression for 2SLS estimation. Default to FALSE.

orthog

A character value(s) specifying the exogenous variables whose exogeneity is to be tested. A C-statistic will be calculated in this case. Default to NULL.

endog

A character value(s) specifying the endogenous variables whose endogeneity is to be tested. A C-statistic will be calculated in this case. Default to NULL.

Value

An object of class fastplm with at least the following properties:

demeaned

A list represents the demeaned linear model. It has, among other properties, x and y, which are the demean result of the input x and y.

coefficients

The coefficients for the demeaned linear model.

sfe.coefs

A list of estimated simple fixed effects. Each is a column vector, in which row names correspond to names of levels in inds. Each, as a list item, has the same name as its effect name in inds. Each vector is centered, i.e. set to have zero mean.

cfe.coefs

A list of estimated complex fixed effects. Each is a matrix in which each row represents a level. The naming convention is the same as in sfe.coefs. There is no centering. Expect an arbitrary intercept.

fitted.values

The fitted values of the fixed effect model.

residuals

The residuals of the fixed effect model, which is numerically the same as the residual of the demeaned linear model.

intercept

The intercept of the fixed effect model. Arbitrary if complex fixed effects are present.

est.coefficients

The estimated coefficients, standard errors and confidence intervals.

vcov

The estimated variance-covariance matrix of estimated coefficients.

R2

Multiple R-squared(original model).

Adj_R2

Adjusted multiple R-squared(original model).

projR2

Multiple R-squared(demeaned model).

projAdj_R2

Adjusted multiple R-squared(demeaned model).

RMSE

Root Mean Square Error.

proj_F_statistic

F-statistic.

variance.type

Type of standard errors and vcov matrices.

num.singletons

Number of singletons(groups with only one observation) the program detected.

drop.index

The original index of dropped singletons.

inds

As in the input.

fe

An object of "fixed.effects" created for intermediate computing.

df.residual

Degree of freedom.

dof

A list that stores the number of categories and the number of redundant categories in each level of fixed effects.

refinement

A list that restores results from wild/pairwise bootsrap refinement.

tests

Only for 2SLS regressions, stores the results of diagnostic tests.

ols.model

Only for 2SLS regressions, stores the results of the simple ols regression (only regress y on x).

reduce.model

Only for 2SLS regressions, stores the results of the reduced-form ols regression (regress y on all exogenous variables z).

names

Only for 2SLS regressions, stores the names of excluded instruments and included instruments.

Examples

data(fastplm)
out <- fastplm(y~x1+x2, index = c("country", "industry", "year"),
               data = simdata1, 
               se = TRUE)

xuyiqing/fastplm documentation built on May 21, 2022, 5:39 a.m.