Reputation: 105
I am trying to run regressions in Stata by company_id
using a large dataset. The goal is to get a line for each company_id
with results of the regression. I am using the following code that gives me the beta coefficient, std error, adj r-squared and N. But I also need to include the Durbin Watson statistic and have not been successful doing that so far. Can someone help? Thanks.
statsby _b _se r2 = e(r2_a) _N, by (company_id) saving($path\SC_results_`i'.dta, replace): regress ret sptr_ret
Upvotes: 0
Views: 328
Reputation: 735
A small program that combines regress
and dwstat
into one command should help. Here's an attempt.
capture program drop reg_dw
program reg_dw, rclass
syntax varlist
regress `varlist'
dwstat
return scalar dw=r(dw)
end
webuse invest2,clear
gen index=_n
tsset index
statsby _b _se r2 = e(r2_a) dw=r(dw) _N, by (company) saving(x.dta, replace): reg_dw invest market
use x, clear
tab _eq2_dw
Upvotes: 2