Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using margins with factor variables after xi: command (qreg2)

    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:
    Code:
    reg y i.x1 i.x2, vce(cluster id)
    margins i.x2, asbalanced
    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
    Code:
    xi: qreg2 i.x1 i.x2, cluster(id)
    which works successfully and gives the desired coefficients, but if I then run
    Code:
    xi: margins i.x2, asbalanced
    I get the error message
    Code:
    variable _Ix1__ not found
    r(111);
    For a solution, I'd either like to know if there is a way to replicate the command
    Code:
    margins i.x2, asbalanced
    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.

  • #2
    Are x1 and x2 0/1 binary variables? Or do they have more than 2 values? It is easier if binary but not impossible otherwise (I think). Something like

    Code:
    reg y x1 x2, vce(cluster id)
    margins, asbalanced at(x2 = (0 1))
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://academicweb.nd.edu/~rwilliam/

    Comment


    • #3
      No, both x1 and x2 have more than 2 values.

      Comment

      Working...
      X