As part of a randomization inference test (https://dimewiki.worldbank.org/Randomization_Inference) -- one that is more complex than -ritest- can accommodate -- I am trying to create a matrix that contains coefficients from a series of individual regressions, each on a different dataset (the observed data, with some random perturbations that fit the context of the test). But I am having trouble figuring out how to enter regression coefficients into a matrix (despite having read up on putmata, and some other commands that I thought might do the trick). I am surely missing something obvious.
The relevant parts of the code are like this:
The lines
returned the error "expression invalid", so I tried replacing those lines with:
And that returned the error " <istmt>: 3499 beta_four not found", which suggests I'm getting somewhere, but it's still an error. How can I enter these coefficients from each regression in the -forval- loop into the matrix?
The relevant parts of the code are like this:
Code:
local sims = 1000 mata:d=J(`sims',2,.) // creates a `sims'x2 matrix of missing values forval i=1/`sims' { use mydata_`i', clear nl (y = {b1}*d1+{b2}*d2+{b3}*d3+{b4}*log(1+{b1}*zo1+{b2}*zo2)+{b5}*log(1+{b1}*zu1+{b2}*zu2)) mata:d[`i',1] = _b[/b4] mata:d[`i',2] = _b[/b5] } clear set obs `sims' getmata (beta_four beta_five) = d
Code:
mata:d[`i',1] = _b[/b4] mata:d[`i',2] = _b[/b5]
Code:
gen beta_four = _b[/b4] gen beta_five = _b[/b5] mata:d[`i',1] = beta_four[1] mata:d[`i',2] = beta_five[1]
Comment