Announcement

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

  • How to make coefplot treat coefficients from different models that have the same regex as the same

    Hello all, could someone help with the following, please?

    Suppose I run two regressions as follows:
    Code:
    eststo m1: reghdfe y  x1_1 x2_1
    eststo m2: reghdfe y  x1_2 x2_2
    I want then to plot these two estimates using coefplot. However, variables x1_1 and x1_2 should be considered the same regressor, likewise for x2_1 and x2_2. That is, my ideal graph would have labels x1 and x2 on the y axis, with 2 models associated to each.

    How can I do that? The estimation procedure cannot be altered, as it is ran in a for loop beforehand and all variables belong to the same dataset.

    I tried using something like
    Code:
    rename(x1_* ="x1" x2_* ="x2", regex) ///
    in the coefplot call, with no results
    Last edited by Arthur Carvalho Brito; 09 Oct 2023, 22:03.

  • #2
    This is just a simple example but I hope it gives you a possible intuition on how to do it.

    Code:
    * Here I just create a dataset similar to yours
    clear 
    set obs 1000
    
    gen x1_1 = runiform()
    gen x2_1 = runiform()
    gen x1_2 = x1_1
    gen x2_2 = x2_1
    
    gen y = x1_1 + x2_1 + rnormal()
    
    
    * Here I run the regression and store the results in a new matrix called beta1 
    eststo m1: reghdfe y  x1_1 x2_1
    matrix beta1= e(b)
    matrix colnames beta1 = "x1" "x2"
    estadd matrix beta = beta1: m1
    
    * Same for model 2
    eststo m2: reghdfe y  x1_2 x2_2
    matrix beta2 = e(b)
    matrix colnames beta2 = "x1" "x2"
    estadd matrix beta = beta2: m2
    
    coefplot m1 m2, b(beta)

    Comment

    Working...
    X