0
votes

I am performing an event study in Stata with the following specification:

reghdfe numPixelsLost tee_1##db_1 tee_2##db_1  tee_3##db_1  tee_4##db_1 tee_5##db_1 tee_6##db_1  tee_7##db_1  tee_8##db_1 tee_9##db_1 tee_10##db_1  if biome==6, absorb(year case_id) vce(cluster case_id) 

When I inspect the full results, I can see that Stata estimated coefficients and standard errors for all of my variables of interest (the interaction terms).

Then I tried to use a loop to take this information and store it as matrices:

forvalues j = 1/10 {
matrix co1`j' = [_b[1.tee_`j'#1.db_1], _b[1.tee_`j'#1.db_1] - 1.96*_se[1.tee_`j'#1.db_1], _b[1.tee_`j'#1.db_1] + 1.96*_se[1.tee_`j'#1.db_1]]
}

Then I then try to stitch all of these matrices together into one matrix (that I can use to make graphs) like this:

matrix all1 =  [co11 \ co12 \ co13 \ co14 \ col5 \ col6 \ col7 \ col8 \ col9 \ col10]

But Stata will not produce the matrix because it claims some of the vectors are "not found". That is odd since all of the coefficients are estimated. I'd like help understanding why the loop does not seem to recognize estimated coefficients and how to produce the matrix.

1
This is on its face contradictory or implying that Stata is more confused than you are. In my experience it's the other way round, usually. More seriously, we can't explore this fully without a reproducible example, which is certainly hard for you to give in this case. But a matrix dir should throw some light on this, as it should show whether col1 to col10 do not all exist (and are of the same size and shape). The immediate problem is whether those vectors are all visible. which Stata appears to be denying; what reghdfe did or did not do upstream may then come into play.Nick Cox
That said, I think the answer is just typos. You are mixing col and co1 as prefix, i.e. confusing letter l and numeral 1.Nick Cox

1 Answers

1
votes

It looks like your problem was solved, but I will add a solution that would take advantage of the stored results from reghdfe and some linear algebra. Also note that you are using 1.96 to construct your confidence intervals which, depending on the number of observations and regressors, may not be a good approximation for the underlying t-distribution.

sysuse auto, clear
reghdfe price weight length, absorb(rep78)

* SET T stat
global sig= 0.95 
scalar _df = e(df_r) // df scalar
scalar _t = abs(invt(_df,(1 - ${sig})/2)) // t stat scalar

* SET BETA AND SE MATRICES
local names : colfullnames e(b)
matrix B = (e(b))'
mata st_matrix("SD_matrix",sqrt(diagonal(st_matrix("e(V)"))))

* IDENTITY MATRIX FOR CONFORMABILITY
matrix I = I(`= rowsof(B)')

* MAKE Confidence interval MATRICES
matrix CI_low = B - _t*I*SD_matrix
matrix CI_high = B + _t*I*SD_matrix

* Final Results
matrix all1 = [B' \ CI_low' \ CI_high']
matrix rownames all1


                 weight      length       _cons
       Beta   5.4783091  -109.50651   10154.617
 CI_.95_Low    3.162337  -187.98821   1617.9601
CI_.95_High   7.7942812   -31.02482   18691.274

This will allow you to recreate the matrix if you alter the number of regressors.