Maarten--
I think it is dangerous to start by using -recode- (what if sample==0
means something else already? what if there are multiple other values
of sample in the data?) but you could achieve the desired effect with:
g s2=sample-1 if inlist(sample,1,2)
gen s2x = s2*x
reg y s2 x s2x
test s2x
While I, like Maarten, prefer the interacted version, one can also get
the test Dirk actually requested using -suest- (see the help file):
sysuse auto, clear
reg pr mpg if for==1
est sto f1
reg pr mpg if for==0
est sto f0
suest f0 f1
test [f0_mean]mpg=[f1_mean]mpg
g formpg=fore*mpg
reg pr mpg fore form
test form
Note that these approaches differ slightly, as the -suest- approach
does not constrain the variance of the residual to be the same across
subsamples.
On 5/2/07, Maarten buis <[email protected]> wrote:
--- Dirk Nachbar <[email protected]> wrote:
> I run OLS regression on two subsamples and I want to test whether the
> coefficients in each regression are the same. I have problems with
> the store and test lines (see code below). How can I do it?
>
> reg y x if sample==1
> estimates store model1
> reg y x if sample==2
> test model1(x)==_x
It is much easier to do this in one model with an interaction term. You
would type the following:
recode sample = (1=0) (2=1)
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/