Learn R Programming

McSpatial (version 1.1.1)

qregsim1: Changes in Distributions Implied by Quantile Regression Estimates

Description

Uses quantile regression results to simulate the effects of an explanatory variable on the distribution of the dependent variable.

Usage

qregsim1(formall, formx, bmat, xmin=NULL, xmax=NULL, 
  graphx=TRUE, graphb=TRUE, graphy=TRUE, graphxb=TRUE, graphols=FALSE,
  histogram=FALSE, histfreq=FALSE, yname=NULL, xname=NULL, nsim=20000, 
  bwadjust=1, data=NULL)

Arguments

formall
Formula with the dependent variable and all explanatory variables, as provided to the qregbmat command.
formx
The explanatory variable to be analyzed. Specified as a formula, e.g., formx=~x.
bmat
Matrix of coefficient estimates from the qregbmat command.
xmin
Lower value of the explanatory variable for discrete changes.
xmax
Upper value of the explanatory variable for discrete changes.
graphx
If graphx=T, presents the kernel density function for the explanatory variable.
graphb
If graphb=T, presents graph of the estimated quantile coefficients.
graphy
If graphy=T, presents density functions for the actual and predicted values of the dependent variable.
graphxb
If graphxb=T, presents graphs of the counterfactual predictions.
graphols
If graphols=T, OLS density estimates are added to all graphs.
histogram
If histogram=T and graphx=T, the density function for the explanatory variable is presented as a histogram. Not relevant if graphx=F.
histfreq
If histogram=T and graphx=T, the histogram is presented using frequencies rather than densities. Not relevant if graphx=F or histogram=F.
yname
A label used for the dependent variable in the density graphs, e.g., yname = "Log of Sale Price".
xname
A label for graphs involving the explanatory variable, e.g., xname = "x1".
nsim
Number of simulations for quantile distributions. Default: nsim=20000.
bwadjust
Factor used to adjust bandwidths for kernel densities. Smoother functions are produced when bwadjust>1. Passed directly to the density function's adjust option. Default: bwadjust=1.
data
A data frame containing the data. Default: use data in the current working directory.

Value

  • xtargetThe values for the horizontal axis of the quantile counterfactual density graphs.
  • densx1Counterfactual density function. When xmin=NULL and xmax=NULL, densx1 is the density function for the predicted values, $X \beta$, when X is drawn from the actual values and $\beta$ is drawn bmat. Otherwise, densx1 is the density function when the x specified by formx is set to xmin while $\beta$ values are drawn from bmat and all other X variables are drawn from their actual values.
  • densx2Counterfactual density function. When xmin=NULL and xmax=NULL, densx2 is the density function for the predicted values, $X \beta$, when the x specified by formx is set to its mean value while $\beta$ values are drawn from bmat and all other X variables are drawn from their actual values. Otherwise, densx2 is the density function when when the x specified by formx is set to xmax.
  • ytargetThe values for the horizontal axis for the density functions for the actual and predicted values of the dependent variable. ytarget=NULL if graphy=F.
  • densy1The values of the density function for the actual values of the dependent variable. densy1=NULL if graphy=F.
  • densy2The values of the density function for the quantile regression predictions of the dependent variable. densy2=NULL if graphy=F.

Details

The qregsim1 function uses a simulation procedure based on the Machado-Mata (2005) approach to simulate the effect of an explanatory variable on the distribution of the dependent variable. The command is intended to follow the qregbmat command. The following results are produced: 1. The estimated density function for the explanatory variable (if graphx=T). Presented as a histogram if histogram=T. 2. The estimated quantile regression coefficients for the variable specified by formx. This graph is produced if graphb=T. 3. Graphs of the density functions for the actual values of the dependent variable and the predicted values from the OLS (if olsgraph=T) and quantile regressions. Using a procedure based on Machado-Mata (2005), the X matrix used for the quantile predictions is based on nsim random draws with replacement from the original matrix of explanatory variables. Similarly, the coefficients are based on nsim draws with replacement from the matrix of estimated quantile regression coefficients, which are supplied by bmat. The OLS estimates are based on the actual values of X rather than on simulated values. 4. The counterfactual density functions. To illustrate how these functions are calculated, consider a simple case in which the full model estimated by qregmat has two explanatory variables, x1 and x2, and suppose that formx=~x1 for the qregsim1 command. The density functions differ depending on whether values are specified for xmin and xmax: Case 1: xmin=NULL and xmax=NULL. In this case, the base set of predicted values of y1 = x1*b1 + x2*b2 is calculated using nsim draws with replacement from the original set of values for x1 and x2 and from the quantile regression estimates of b1 and b2. The alternative (i.e., counterfactual) set of predicted values is calculated using the mean value of x1 in place of the random draws, i.e., y2 = mean(x1)*b1 + x2*b2. The coefficients, b1, are evaluated at the same set of random draws as used for the base set of predictions. A similar procedure is used for the OLS predictions if olsgraph=T, but the explanatory variables are evaluated at actual values rather than randomly drawn values. The density function for the base set of quantile predicted values is stored in densx1 and the density function for the quantile predictions with x1 set to mean(x1) is stored in densx2. Case 2: Values specified for xmin and xmax. In this case, the base set of predicted values is y1 = xmin*b1 + x2*b2, with x2, b1, and b2 drawn with replacement from the original values. The alternative set of predicted values is y2 = xmax*b1 + x2*b2. The density function for y1 is stored in densx1 and the density function for y2 is stored in densx2. A similar procedure is used for the OLS predictions if olsgraph=T, but x2 is evaluated at actual values rather than randomly drawn values. This procedure is comparable to calculating a discrete derivative. Case 3: Value specified for one of xmin or xmax while the other equals NULL. This case is equivalent to case 2 with xmin set to x1 while $xmax = x1 + \delta$, where $\delta$ is the value provided by the non-NULL value. For example, if xmin=1 and xmax = NULL, the density functions are evaluated at y1 = x1*b1 + x2*b2 and y2 = (x1+1)*b1 + x2*b2. The same results would be produced by xmin = NULL and xmax=1. As in case 2, quantile estimates are evaluated at simulated values for x1 and x2 while OLS estimates are presented at actual values.

References

Koenker, Roger. Quantile Regression. New York: Cambridge University Press, 2005. 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.

See Also

qregbmat qregsim2 qregcpar qreglwr

Examples

Run this code
par(ask=TRUE)
data(matchdata)
matchdata$age <- matchdata$year - matchdata$yrbuilt 
bmat <- qregbmat(lnprice~lnland+lnbldg+age+factor(year), data=matchdata,
  graph.factor=TRUE)

fit <- qregsim1(lnprice~lnland+lnbldg+age+factor(year),~lnland, bmat, 
  data=matchdata)
lo = signif(quantile(matchdata$lnland,.25),4)
hi = signif(quantile(matchdata$lnland,.75),4)
#Simulation for 1995
smalldata <- matchdata[matchdata$year==1995,]
bmat95 <- bmat[,1:4]
fit <- qregsim1(lnprice~lnland+lnbldg+age,~lnland, bmat95, 
  xmin=lo, xmax=hi, data=smalldata)
#Simulation for 2005
smalldata <- matchdata[matchdata$year==2005,]
bmat05 <- bmat[,1:4]
bmat05[,1] <- bmat05[,1] + bmat[,5]
fit <- qregsim1(lnprice~lnland+lnbldg+age,~lnland, bmat05, 
  xmin=lo, xmax=hi, data=smalldata)

Run the code above in your browser using DataLab