# Industry and Year Fixed Effects

I hope someone can help me as I am stuck with this problem for quite some time.

I have panel of S&P500 companies from 2010 - 2014 and I want to run a regression including industry and year fixed effects.

I am a beginner in panel data analysis and also Stata, and I cant find the answer anywhere. I am so confused as I am not sure whether industry and year fixed effects are equivalent to cross-section and period fixed effects.

Let's say you have some category variable $c_i$ (eg. c may be the industry company $i$ is in). An important mathematical point to keep in mind is that running a fixed effects regression with fixed effects for $c$ is equivalent to running a regular regression with indicator variables for each possible value of $c$.

A basic strategy might be to:

1. use xtset industryvar in Stata to indicate you want fixed effects for each unique value of industryvar.
2. Generate dummy variables for every year.
3. Call xtreg with the fe option to indicate fixed effects, including the dummy variables for year as right hand side variables.

More explicitly, you might do something like:

xtset industry
xtreg y x1 x2 i.year, fe


This assumes year is a variable which holds the year, industry is a variable that holds the industry etc...

• Dear Matthew, thank you so much for your helpful answer. I tried as you advised in Stata, and i am happy with the result i get. Would you mind If i check once again with you - I have 418 companies from S&P 500 index, over 5 years 2020 - 2014, and I have downloaded SIC codes for each company to control for industry effects. Thus I have done : xtset sic ; xtreg y x1 x2 x3 ... i.year, fe I apologise in advance if my question seems silly to you, but I am an absolute beginner and dont have anyone at my Uni who can help me out with Panel. Kind regards, Milica – Milica Matovic May 12 '16 at 12:36
• yeah, that's how you would do that. Another random thought, you could use 4 digit SIC codes or you could also try 3 digit sic codes (eg. generate a new variable SIC3 by taking the 4 digit code, dividing by 10 and lopping off the remainder with the floor() function i.e. gen sic3 = floor(sic4/10)). – Matthew Gunn May 12 '16 at 17:13
• Thank you for your kind and helpful answer. Best regards, Milica – Milica Matovic May 14 '16 at 10:15

In this context, a fixed effect regression (or within estimator) is a method for modelling with panel or longitudinal data. This estimator differences out the average of the observational unit's variables from each variable:

For individuals $i \in 1\dots N$, observed in periods $1\dots T$, and covariates $X_k$, and dependent variable $Y$, the fixed effect estimator performs the following transformation:

$\breve{Y}_{it} = Y_{it} - \bar{Y}_i$ and
$\breve{X}_{kit} = X_{kit} - \bar{X}_{ki}$ for $k = 1\dots K$

The regression is performed on the transformed variables. In stata, this is implemented using the xtreg command with the fe option.

This command will probably not work in your situation, since it is designed for differencing out averages for each observational unit. It is likely that you will have multiple companies that operate in a particular industry and you want to difference out the industry average. This is a simple case of a hierarchical linear model.

In this situation, you want to use the i. operator in Stata:

reg y i.industry i.year


You could also use the areg command to get identical results:

areg y i.year, absorb(industry)


The areg command can be useful when the number of levels of the absorbed variable (the number of industries in this example) is high.

If it is true that there are multiple firms within the same industry as I suspect to be the case, then it is a common practice, which is good sense and asymptotically supported, to cluster your standard errors at the industry level. In stata, this is typically accomplished with the vce(cluster varname) option. So, for example, your regress command would become

reg y i.industry i.year, vce(cluster industry)


On a similar note, a fairly recent development has been made in constructing two-way and multiway cluster robust standard errors (See, for example, the Cameron, Gelbach, and Miller's 2011 paper in the Journal of Business and Economic Statistics). If you are worried about shocks that affect the entire set of stocks in a given time period, this may be worth implementing. Doug Miller wrote an .ado file called cgm.ado that implements one method of multiway clustering.

• I would also suggest clustering the errors if this approach is followed. – Dimitriy V. Masterov May 10 '16 at 0:56
• That's true. I thought about adding this suggestion, but refrained as maybe outside of scope. I'll add it in. – lmo May 10 '16 at 11:14
• I'm struggling to see how xtreg ,fe is at all inappropriate since reg y x i.industry i.year, vce(cluster industry) will generate identical estimates for x as xtset industry followed by xtreg y x i.year, vce(robust). Including dummies or demeaning based upon id is the exact same thing from a mathematical, linear algebra perspective. In fact, for large numbers of dummy variables, the xtreg will compute faster because 10000 fixed effects + 2 variables of interest would involve solving a 10002 variable system while would only be a 2 variable system on the transformed data. – Matthew Gunn May 12 '16 at 17:23
• @MatthewGunn I agree with you in the case that industry is an observational unit which is observed over time. However, when there are multiple observational units (firms) per industry, then the typical FE discussion and xtreg .., fe have to be adjusted. Running xtset in such a case results in an error.: "repeated time values within panel." – lmo May 12 '16 at 18:19
• you can have multiple firms per industry. That's fine, just don't set tsset too. – Matthew Gunn May 12 '16 at 18:47