Comments (7)
I suppose this is a similar question - is adding fixed effects for a variable (functionally) just adding a bunch of indicators for that variable (i.e., is year fixed effects just having a coefficient on whether or not the year is 1987, whether or not the year is 1988,etc)? If that's the case, then
reg = smf.ols('fatalityrate ~ sb_useage+state+str_year+speed65+speed70+ba08+drinkage21+log_income+age', seatbelts).fit()
works fine (where str_year was generated by
seatbelts['str_year'] = seatbelts['year'].apply(str))
But if I've misinterpreted what fixed effects are, then that might not be what we want
from comp-econ-sp19.
Hi @jwhitty32 . Are you referring to https://github.com/jmbejara/comp-econ-sp19/blob/master/lectures/4-23_Panel_Data/Fixed-and-Random-Effects-Rosetta-Stone.ipynb
If not, check that out. It should help.
from comp-econ-sp19.
Hi @richard-archer . The fixed effect is like adding a dummy indicator variable for each year. What you've described isn't quite that. You would need a binary indicator for each year (leaving one out to avoid collinearity). However, note that adding an indicator for each variable forces Python to run the regression in a way that might not be computationally efficient. Using the proper fixed effects method will perform the calculation efficiently.
from comp-econ-sp19.
I see. To perform that regression in a computationally efficient way, we should use something of the form:
reg = linearmodels.PanelOLS.from_formula("y~ x1+ x2+ EntityEffects + TimeEffects", data=df)
? That's the example that was provided, but I don't understand how python would identify (or rather, how we should designate) what should be treated as the entity effects and what should be treated as the time effect
from comp-econ-sp19.
Right. It uses the variables in the DataFrame index. When there are two, you need a pandas multi-index.
from comp-econ-sp19.
I can't remember the ordering off the top of my head. I have poor connectivity right now to look it up. The first level of the multi-index might be the time effects and the other the entity effects. The names don't matter so much, as long as you treat them consistently.
from comp-econ-sp19.
Are state fixed effects the same as entity effects? When you say add "firm fixed effects" or "state fixed effects" how does that change the linearmodels.PanelOLS.from_formula inputs? The panel data lecture is quite confusing to me.
For example, Question 2 asks to consider state fixed effects. Below, seatb is the name of the data:
seatb2 = seatb[['fatalityrate' , 'sb_useage', 'speed65', 'speed70', 'ba08', 'drinkage21','log_income', 'age']].dropna()
reg = linearmodels.PanelOLS.from_formula("fatalityrate ~ sb_useage+ speed65 + speed70+ ba08+ drinkage21+log_income+age + EntityEffects", data=seatb2)
This produces an error in the second line:
Error evaluating factor: NameError: name 'fatalityrate' is not defined
0 + fatalityrate
^^^^^^^^^^^^
from comp-econ-sp19.
Related Issues (20)
- mle_args HOT 1
- Dealing with NaN Values HOT 3
- Correct Queries, Consistent Issues Running Database HOT 1
- Optimizer not working but generating correct log-likelihood values HOT 1
- Kaggle Not Running HOT 1
- wrong value for Q1 HOT 3
- Ari's monday office hours HOT 1
- Difference between value function and policy function HOT 1
- McCall Wage Values HOT 2
- Typo in HW 7
- HW7 eatCake graphs & output HOT 1
- McCall Modification HOT 1
- EatCake Problem 1 HOT 3
- Replicate Bresnahan Reiss-1991 Solutions Question HOT 1
- issue with HW7 Q5 HOT 1
- Final Review HOT 1
- Using opt.minimize on discrete data HOT 3
- Questions for Bresnahan HW HOT 1
- office hours today HOT 1
- MLE for Bernoulli distribution HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comp-econ-sp19.