# Re: st: variance components usin xtmixed

 From Joseph Coveney To Statalist Subject Re: st: variance components usin xtmixed Date Wed, 23 Aug 2006 17:31:30 +0900

```Huseyin Tastan wrote:

I want to analyze variance components of a measure of firm performance (such
as return on equity) using random effects at three levels: industry level,
firm level and time level.

I have data on

industries: i=1,2,...,20 (there are 20 industries)

firms: j=1,2,...,1000 (there are 1000 firms)

and

years: t=1,2,...,10 (there are 10 years)

The specific model is written as follows:

y_ijt = a + b_i + c_j + d_t + e_ijt

There are four variances to estimate in this model:

var(y) = var(b) + var(c) + var(d) + var(e)

I have tried xtmixed to estimate this model but the convergence was
extremely slow (I used reml option). And for some dependent variables it
didnt even converge. The command I used was something like this:

xtmixed y || industry: || firm: || year:, variance

This assumes that year is nested within firms and firm is nested within
industries. Hence, when one changes the nesting structure variance estimates
dramatically change. I also tried the following model which takes the data
as one big group:

xtmixed y || _all: R.industry || _all: R.firm || _all: R.years

Is there another way to estimate these four variance components in STATA
using xtmixed or some other routine?

--------------------------------------------------------------------------------

effects are all crossed (random firms, each participating in multiple random
industries on average, each for multiple random years on average).  So your
second syntax with -xtmixed- would be the one to use.  I'm no
econometrician, but it still seems odd to treat time as a variance
component.

As to your question about another way, you can use method of moments, which
is noniterative and wouldn't have convergence problems.  Below I show an
example for a balanced dataset of each of 1000 firms participating in each
of 20 industries for each of 10 years.  For the unbalanced case, which you
undoubtedly have, you can get the expectations of the mean squares by the
method described in Chapter 18 of G. A. Milliken and D. E. Johnson,
_Analysis of Messy Data, Volume 1-Designed Experiments_ (Boca Raton, Fla.:
Chapman & Hall/CRC, 1992).  The method of moments is apparently popular
among econometricians, so you might already have at hand a better reference
for unbalanced cases.

Joseph Coveney

clear
set more off
set matsize 11000
set seed `=date("2006-08-23", "ymd")'
tempfile tmpfil0
set obs 1000
generate int firm_j = _n
generate float firm_u = invnorm(uniform())
quietly summarize firm_u
display in smcl as result %4.2f r(sd)^2
save `tmpfil0'
drop _all
set obs 20
generate byte industry_i = _n
generate float industry_u = invnorm(uniform())
quietly summarize industry_u
display in smcl as result %4.2f r(sd)^2
cross using `tmpfil0'
save `tmpfil0', replace
drop _all
set obs 10
generate byte year_t = _n
generate float year_u = invnorm(uniform())
quietly summarize year_u
display in smcl as result %4.2f r(sd)^2
cross using `tmpfil0'
erase `tmpfil0'
generate float response = year_u + industry_u + firm_u + ///
invnorm(uniform())
anova response industry_i firm_j year_t
scalar MSyear = e(ss_3) / e(df_3)
scalar MSfirm = e(ss_2) / e(df_2)
scalar MSindustry = e(ss_1) / e(df_1)
scalar MSerror = e(rss) / e(df_r)
display in smcl as text "   Error Variance: " ///
as result %4.2f scalar(MSerror)
display in smcl as text "    Year Variance: " ///
as result %4.2f (scalar(MSyear) - scalar(MSerror)) / ///
(1 * 20 * 1000)
display in smcl as text "    Firm Variance: " ///
as result %4.2f  (scalar(MSfirm) - scalar(MSerror)) / ///
(1 * 20 * 10)
display in smcl as text "Industry Variance: " ///
as result %4.2f  (scalar(MSindustry) - scalar(MSerror)) / ///
(1 * 1000 * 10)
exit

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