# Re: st: RE: RE: variable mean and r(mean), why do they differ?

 From mindy.nitkin@simmons.edu To statalist@hsphsun2.harvard.edu Subject Re: st: RE: RE: variable mean and r(mean), why do they differ? Date Fri, 25 Nov 2005 13:56:18 -0500

```I am using the program below to complete industry level regressions and then to
apply the coefficiencts from the industry regressions to firms within each
industry in order to predict the level of TA. It works very well.

I am wondering if there is a way to imput the regression coefficents into my
data set as variable for each firms observation in addition to or instead of
the predictions.

Alternately, can Stata use the coefficients from the first regression:
TA REV PPE in a second regressioin: TA (REV-AR) PPE. The model I am trying to
replicate changes between in first stage and second stage regressions.

Mindy Nitkin

clear
use "C:\Program Files\Stata9\data\GEINDEX\EQ4_1985_2004.dta"
tempvar id
sort SIC
by SIC: gen `id'=1 if _n==1
qui replace `id'=sum(`id')
local i=0
tempvar pred0
qui gen `pred0'=.
local n=`id'[_N]
while `i'<`n' {
local i=`i'+1
local j=`i'-1
tempvar pred pred`i'
qui regress TA REV PPE if `id'--`i'
qui predict `pred' if `id'==`i', xb
qui egen `pred`i''=rmax(`pred' `pred`j'')
drop `pred' `pred`j''
}
rename `pred`i'' pred
save "C:\Program Files\Stata9\EQ4\EQ4_1985_2004.dta", replace

Quoting Raoul C Reulen <r.c.reulen@bham.ac.uk>:

> Thanks Maarten,
>
> In my analysis it does make a difference. I have to calculate numerous
> mean values, sum them to obtain one variable and then I have to multiply
> this by a large factor before I can use it. Any suggestions? Thanks
> again.
>
> Raoul
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Maarten Buis
> Sent: 25 November 2005 09:08
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: variable mean and r(mean), why do they differ?
>
> Raoul:
>
> Your hunch seems to be correct:
>
> sysuse auto, clear
> sum price
> gen price2 = price - r(mean)
> gen double price3 = price - r(mean)
>
> sum price2 price3
>
> However note that the difference in the highest and lowest price is
> aprox. 1,200 dollar and that price2 is different from zero in only the
> fifth decimal place, so I would consider that zero for any practical
> application.
>
> HTH,
> Maarten
>
> -----------------------------------------
> Maarten L. Buis
> Department of Social Research Methodology Vrije Universiteit Amsterdam
> Boelelaan 1081
> 1081 HV Amsterdam
> The Netherlands
>
> Buitenveldertselaan 3 (Metropolitan), room Z214
>
> +31 20 5986715
>
> http://home.fsw.vu.nl/m.buis/
> -----------------------------------------
>
> > -----Original Message-----
> > From: owner-statalist@hsphsun2.harvard.edu
> > [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Raoul C
> > Reulen
> > Sent: vrijdag 25 november 2005 9:43
> > To: statalist@hsphsun2.harvard.edu
> > Subject: st: variable mean and r(mean), why do they differ?
> >
> > If I want to save the mean of a variable into a new variable, I would
> first:
> > sum var1
> > gen var2, r(mean)
> > But if I subtract var1-var2, the outcome is almost, but not exactly
> "0". How can make sure that both means are equal?
> > I have tried .round, .int. , but that doesn't work. Do I have to
> change the storage type? Thanks for the advice.
>
>
> *
> *   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/
>
> *
> *   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/
>

*
*   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/
```