View source: R/causeSum2Panel.R
causeSum2Panel | R Documentation |
The algorithm of this function uses an internal function fminmax=function(x)min(x)==max(x). The subsets mtx2 of the original data da for a specific time or space can become degenerate if the columns of mtx2 have no variability. The apply function of R is applied to the columns of mtx2 as follows. "ap1=apply(mtx2,2,fminmax)." Now, "sumap1=sum(ap1)" counts how many columns of the data matrix are degenerate. We have a degeneracy problem only if sumap1 is >1 or =1. For example, the panel consists of data on 50 united states and 20 years. Now consumer price index (cpi) data may be common for all states. That is, the min(cpi) equals max(cpi) for all states. Then the variance of cpi is zero, and we have degeneracy. When this happens, the regressor cpi should not be involved in determining causal paths. We identify degeneracy using "fminmax=function(x)min(x)==max(x)"
causeSum2Panel(
da,
fn,
rowfnout,
colfnout,
fnoutNames,
namXs,
namXt,
namXy,
namXc = NULL,
namXjmtx,
chosenTimes = NULL,
chosenSpaces = NULL,
ylag = 0,
verbo = FALSE
)
da |
panel dat having a named column for space and time |
fn |
an R function causeSummary2(mtx) |
rowfnout |
the number of rows output by fn |
colfnout |
the number of columns output by fn |
fnoutNames |
the column names of output by fn, for example, fnoutNames=c("cause","effect","strength","r","p-val") |
namXs |
title of the column in da having the space variable |
namXt |
title of the column in da having the time variable |
namXy |
title of the column in da having the dependent y variable |
namXc |
title(s) of the column(s) in da having control variable(s) |
namXjmtx |
title(s) of the column(s) in da having regressor(s) |
chosenTimes |
subset of values of time variable chosen for quick results, There are NchosenTimes values chosen in the subset. default=NULL means all time identifiers in the data are included. |
chosenSpaces |
subset of values of space variable chosen for quick results, There are NchosenSpaces values chosen in the subset. default=NULL means all space identifiers are included. |
ylag |
time lag in Granger causality study of time dimension the default ylag=0 means ylag=min(4, round(NchosenTimes/5,0)) where NchosenTimes is the length of chosenTimes vector |
verbo |
print detail results along the way, default=FALSE |
We assume that panel data have space (space=individual region) and time (e.g., year) dimension, and We use upper case X to denote a common prefix in the panel data. Xs =name of the space variable, e.g., state or individual. The range of values for s is 1 to nspace. Xt =name of the time variable, e.g., year. The range of values for t is 1 to ntime. Xy =the dependent variable(s) value at time t in state s. Since panel data causal analysis can take a long computer time, we allow the user to choose subsets of time and space values called chosenTimes and chosenSpaces, respectively. Various input parameters starting with "nam" specify the names of variables in the panel study.
The algorithm calls some function fn(mtx) where mtx is the data matrix, and fn is causeSummary2(mtx). The causal paths between (y, xj) pairs of variables in mtx are computed following 3 sophisticated criteria involving exact stochastic dominance. type "?causeSummary2" on the R console to get details (omitted here for brevity). Panel data consist of a time series of cross-sections and are also called longitudinal data. We provide estimates of causal path directions and strengths for both the time-series and cross-sectional views of panel data. Since our regressions are kernel type with not functional forms fixed effect for time and space are being suppressed when computing the causality.
The causeSum2Panel() produces three output matrices. The first "outt" gives panel causal path output focused on time series for each space value using fixed space value. It reports causal path directions, and strengths for (y, xj) pairs. The second output matrix called "outs" gives panel causal path output focused on space cross sections using fixed time value. The third output matrix called "outdiff" gives causal paths using Granger causality for each pair (y, xj).
The function prints to the screen some summaries of the three output matrices. It reports how often a variable is a cause in various pairs as time series or as cross sections. It also reports the average strengths of causal paths for "outt" and "outs" matrices. If the averages in "outdiff" matrix are negative, the Granger causal paths go from y to xj. This may be unexpected when the model assumes that y depends on x1 to xp,and One expects the causal paths from xj to y. In studying the causal pairs, the function creates mixtures of names y and xj. Character vectors containing the mixed names used are also a part of the output. The vectors are named mixnam2t for time series and mixnam2s for cross-section portion of panel data. The two sets of mixed names are needed because degeneracies on the time dimension may be the same as degeneracies on the space dimension.
Prof. H. D. Vinod, Economics Dept., Fordham University, NY.
Vinod, H. D. 'Generalized Correlation and Kernel Causality with Applications in Development Economics' in Communications in Statistics -Simulation and Computation, 2015, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/03610918.2015.1122048")}
Vinod, H. D. 'New exogeneity tests and causal paths,' Chapter 2 in 'Handbook of Statistics: Conceptual Econometrics Using R', Vol.32, co-editors: H. D. Vinod and C.R. Rao. New York: North Holland, Elsevier Science Publishers, 2019, pp. 33-64.
Vinod, H. D. Causal Paths and Exogeneity Tests in Generalcorr Package for Air Pollution and Monetary Policy (June 6, 2017). Available at SSRN: https://www.ssrn.com/abstract=2982128
Vinod, Hrishikesh D., R Package GeneralCorr Functions for Portfolio Choice (November 11, 2021). Available at SSRN: https://ssrn.com/abstract=3961683
Vinod, Hrishikesh D., Stochastic Dominance Without Tears (January 26, 2021). Available at SSRN: https://ssrn.com/abstract=3773309
See causeSummary2
See causeSummary
is subject to trapezoidal approximation.
## Not run:
library(plm);data(Grunfeld)
options(np.messages=FALSE)
namXs="firm"
print("initial values identifying the space variable")
head(da[,namXs],3)
print(str(da[,namXs]))
chosenSpaces=(3:10)
if(is.numeric(da[,namXs])){
chosenSpaces=as.numeric(chosenSpaces)}
if(!is.numeric(da[,namXs])){
chosenSpaces=as.character(chosenSpaces)}
namXt="year"
print("initial values identifying the time variable")
head(da[,namXt],3)
print(str(da[,namXt]))
chosenTimes=1940:1949
if(is.numeric(da[,namXt])){
chosenTimes=as.numeric(chosenTimes)}
if(!is.numeric(da[,namXt])){
chosenTimes=as.character(chosenTimes)}
namXy="inv"
namXc=0
namXjmtx=c("value","capital")
p=length(namXjmtx)
fn=causeSummary2
fnout=matrix(NA,nrow=p,ncol=5)
fnoutNames=c("cause","effect","strength","r","p-val")
causeSum2Panel(da, fn=causeSummary2,
rowfnout=p, colfnout=5,
fnoutNames=c("cause","effect","strength","r","p-val"),
namXs=namXs,
namXt=namXt,
namXy=namXy,
namXc=namXc,
namXjmtx=namXjmtx,
chosenTimes=chosenTimes,
chosenSpaces=chosenSpaces,
verbo=TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.