I am attempting to capture p-values (for a coefficient, not the model) after a regression into a postfile:
Clearly something is going wrong with the matrix / r(table) steps. There are several threads with similar problems, but I'm think I'm missing something obvious?
Code:
// clear all
*prelims
sysuse auto, clear
regress mpg ib1.foreign
matrix list r(table)
*define program
capture program drop regress1
program define regress1, rclass // eclass ?
replace mpg = mpg * rpoisson(2)
regress mpg ib1.foreign
end
set seed 1234
* create postfile
tempname sim_file
postfile sim_file p using "mysim.dta", replace
* run program & extract p into postfile
forvalues i=1/10 {
drop _all
quietly regress1
tempname M
matrix `M' = r(table)
return scalar p = `M' [4,1]
post sim_file (`p')
}
postclose sim_file
use mysim.dta, clear
sum p

Comment