Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: Subtracting out many fixed effects

 From Chris Parker To statalist@hsphsun2.harvard.edu Subject st: Subtracting out many fixed effects Date Mon, 21 Jun 2010 08:48:06 +0100

```Hi Statalisters,

I'm trying to run a panel regression with a large number of fixed
effects in addition to the group fixed effects that xtreg takes care
of for me.  Because of the large number of variables I cross the limit
on matsize of 11,000.  I have therefore opted to subtract out some of
the fixed effects.  My problem is that I don't know the best way to do
this when there are multiple fixed effects to be subtracted out.

I created a small example to demonstrate the problem.  In the example
I trying to predict income by education (edu) and 2 dummy variable:
male and topper (topper being someone at the top of their class).  I
can recreate the initial regression by subtracting out the averages of
income, topper and education using a bysort on male then using regress
on the adjusted values.  However, I want to then subtract out the
average value of topper and regress the twice adjusted values of
income and education.  I've tried this two ways below and neither
works.  The first way is to subtract out the average adjusted income
and education values using a bysort on the original topper value.  The
second way is to subtract out the average adjusted income and
education values using a bysort on the adjusted topper value.

Can someone explain to me what I'm doing wrong here?

Many thanks,

Chris Parker

________________________________

PhD Candidate | Management Science & Operations
London Business School | Regent's Park | London NW1 4SA | United Kingdom
Direct line +44 (0)20 7000 8816 | Email cparker.phd2007@london.edu

---------------------------------------------------------------
* Initial Regression trying to replicate
reg income edu male topper

* Subtract out aveincome, aveedu and avetopper by male
bysort male: egen aveincome=mean(income)
gen income2=income-aveincome
drop aveincome

bysort male: egen avetopper=mean(topper)
gen topper2=topper-avetopper
drop avetopper

bysort male: egen aveedu=mean(edu)
gen edu2=edu-aveedu
drop aveedu

* This replicates the first regression as theory suggests
reg income2 edu2 topper2

* Try my way to replicate the first regression
bysort topper: egen aveincome=mean(income2)
gen income3=income2-aveincome
drop aveincome

bysort topper: egen aveedu=mean(edu2)
gen edu3=edu2-aveedu
drop aveedu

* Doesn't do what you want it to...
reg income3 edu3

* Try subtracting out by topper2 as suggested
bysort topper2: egen aveincome=mean(income2)
gen income4=income2-aveincome
drop aveincome

bysort topper2: egen aveedu=mean(edu2)
gen edu4=edu2-aveedu
drop aveedu

* Still doesn't replicate what you want
reg income4 edu4

---------------------------------------------------------------
This is the data I am using for the example

Income	Edu	Male	Topper
7	3	0	0
7.7	3	0	0
8.1	4	0	0
8.2	5	0	0
9.1	6	0	0
12	7	0	0
12.4	7	0	0
14.6	8	0	0
15.1	9	0	0
15.6	9	0	0
17	10	0	0
17.2	10	0	0
19.9	11	0	0
22	12	0	0
23	12	0	0
26	13	0	0
27	13	0	0
29	14	0	0
30	14	0	0
5	2	0	1
9.2	2	0	1
10	4	0	1
12	5	0	1
12	6	0	1
16	8	0	1
21	11	0	1
13	4	1	0
15	6	1	0
17	8	1	0
19	9	1	0
25	11	1	0
33	13	1	0
12	3	1	1
18	7	1	1
14	2	1	1
17	5	1	1
27	10	1	1
31	12	1	1
40	14	1	1
---------------------------------------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```