I am regressing an outcome (y) on two categorical variables (x1, x2), with standard errors clustered by a third variable (id). I am interested in the predicted values of y at each level of x2, with the average value of x1. I therefore run the commands:
This produces the results I want and works without issue.
My problem arises when I try to get analogous results, but using quantile (median) regression rather than OLS. Because my standard errors need to be clustered, I have to either use bootstrap or the package qreg2. The margins command works as expected after bootstrap, but with my data bootstrapping takes an inconveniently long time to run. I had hoped to be able to use qreg2 instead. However, qreg2 is incompatible with new stata factor variables, and requires the xi: prefix. I am able to run the regression using qreg2, but I cannot use the margins command after estimation since this depends on factor variables. Specifically, I run
which works successfully and gives the desired coefficients, but if I then run
I get the error message
For a solution, I'd either like to know if there is a way to replicate the command
in a way that is compatible with xi: prefixed estimation commands, or whether there is a way to run quantile regression with clustered standard errors that allows new-style factor variables.
Code:
reg y i.x1 i.x2, vce(cluster id) margins i.x2, asbalanced
My problem arises when I try to get analogous results, but using quantile (median) regression rather than OLS. Because my standard errors need to be clustered, I have to either use bootstrap or the package qreg2. The margins command works as expected after bootstrap, but with my data bootstrapping takes an inconveniently long time to run. I had hoped to be able to use qreg2 instead. However, qreg2 is incompatible with new stata factor variables, and requires the xi: prefix. I am able to run the regression using qreg2, but I cannot use the margins command after estimation since this depends on factor variables. Specifically, I run
Code:
xi: qreg2 i.x1 i.x2, cluster(id)
Code:
xi: margins i.x2, asbalanced
Code:
variable _Ix1__ not found r(111);
Code:
margins i.x2, asbalanced
Comment