qregsim2(formall, formx, dataframe1, dataframe2, bmat1, bmat2, graphx=TRUE, graphb=TRUE, graphy=TRUE, graphdy=TRUE, nbarplot=10, yname=NULL, xnames=NULL, timenames=c("1","2"), leglocx="topright",leglocy="topright",leglocdy="topright", nsim=20000, bwadjx=1,bwadjy=1,bwadjdy=1)
The matrices bmat1 and bmat2 are intended to represent the output from qregbmat. The models must include the same set of explanatory variables, and the variables must be in the same order in both bmat1 and bmat2. In contrast, the data frames dataframe1 and dataframe2 can have different numbers of observations and different sets of explanatory, as long as they include the dependent variable and the variables listed in bmat1 and bmat2.
The output from qregsim2 is a series of graphs. If all options are specified, the graphs appear in the following order:
1. Kernel density estimates for each variable listed in formx. Estimated using density with default bandwidths and the specified value for bwadjx. Not shown if graphx=F. The xnames and leglocx options can be used to vary the names used to label the x-axis and the legend location.
2. Quantile coefficient estimates for the variables listed in formx. Not listed if graphb=F.
3. Kernel density estimates for the predicted values of $X_1\beta_1 + Z_1\gamma_1$ and $X_2\beta_2 + Z_2\gamma_2$, and the counterfactual, $X_1\beta_2 + Z_2\gamma_2$. Estimated using density with default bandwidths and the specified value for bwadjy. Not shown if graphy=F. The label for the x-axis can be varied with the yname option. The three estimated density functions are returned after estimation as yhat11, yhat22, and yhat12.
4. A graph showing the change in densities, d2211 = f22 - f11, along with the Machado-Mata decomposition showing:
(a) the change in densities due to the variables listed in formx: d2212 = f22 - f12.
(b) the change in densities due to the coefficients: d1211 = f12 - f11.
These estimates are returned after estimation as d2211, dd2212, and d1211. The density changes are not shown if graphdy=F. The label for the x-axis can be varied with the yname option. The bandwidth for the original density functions f11, f22, and f12 can be varied with bwadjdy. It is generally desirable to set bwadjdy > bwadjy because additional smoothing is needed to make the change in densities appear smooth.
The distributions are simulated by drawing nsim samples with replacement from xobs1 <- seq(1:n1), xobs2 <- seq(1:n2), and bobs <- seq(1:length(taumat)). The commands for the simulations are:
xobs1 <- sample(seq(1:n1),nsim,replace=TRUE)
xobs2 <- sample(seq(1:n2),nsim,replace=TRUE)
bobs <- sample(seq(1:ntau),nsim,replace=TRUE)
xhat1 <- allmat1[xobs1,]
xhat2 <- allmat2[xobs2,]
znames <- setdiff(colnames(allmat1),colnames(xmat1))
if (identical(znames,"(Intercept)")) xhat12 <- xhat1
if (!identical(znames,"(Intercept)"))
xhat12 <- cbind(xhat2[,znames],xhat1[,colnames(xmat1)])
xhat12 <- xhat12[,colnames(allmat1)]
bhat1 <- bmat1[bobs,]
bhat2 <- bmat2[bobs,]
where allmat and xmat denote the matrices defined by explanatory variables listed in formall (including the intercet) and formx. Since the bandwidths are simply the defaults from the density function, they are likely to be different across regimes as the number of observations and the standard deviations may vary across times. Thus, the densities are re-estimated using the average across regimes of the original bandwidths.
Machado, J.A.F. and Mata, J., "Counterfactual Decomposition of Changes in Wage Distributions using Quantile Regression," Journal of Applied Econometrics 20 (2005), 445-465.
McMillen, Daniel P., "Changes in the Distribution of House Prices over Time: Structural Characteristics, Neighborhood or Coefficients?" Journal of Urban Economics 64 (2008), 573-589.
dfldens
par(ask=TRUE)
n = 5000
set.seed(484913)
x1 <- rnorm(n,0,1)
u1 <- rnorm(n,0,.5)
y1 <- x1 + u1
# no change in x. Coefficients show quantile effects
tau <- runif(n,0,.5)
x2 <- x1
y2 <- (1 + (tau-.5))*x2 + .5*qnorm(tau)
dat <- data.frame(rbind(cbind(y1,x1,1), cbind(y2,x2,2)))
names(dat) <- c("y","x","year")
bmat1 <- qregbmat(y~x,data=dat[dat$year==1,],graphb=FALSE)
bmat2 <- qregbmat(y~x,data=dat[dat$year==2,],graphb=FALSE)
fit1 <- qregsim2(y~x,~x,dat[dat$year==1,],dat[dat$year==2,],
bmat1,bmat2,bwadjdy=2)
# Distribution of x changes. Coefficients and u stay the same
x2 <- rnorm(n,0,2)
y2 <- x2 + u1
dat <- data.frame(rbind(cbind(y1,x1,1), cbind(y2,x2,2)))
names(dat) <- c("y","x","year")
bmat1 <- qregbmat(y~x,data=dat[dat$year==1,],graphb=FALSE)
bmat2 <- qregbmat(y~x,data=dat[dat$year==2,],graphb=FALSE)
fit1 <- qregsim2(y~x,~x,dat[dat$year==1,],dat[dat$year==2,],
bmat1,bmat2,bwadjdy=2)
Run the code above in your browser using DataLab