Giter VIP home page Giter VIP logo

Comments (7)

richard-archer avatar richard-archer commented on July 18, 2024

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.

jmbejara avatar jmbejara commented on July 18, 2024

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.

jmbejara avatar jmbejara commented on July 18, 2024

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.

richard-archer avatar richard-archer commented on July 18, 2024

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.

jmbejara avatar jmbejara commented on July 18, 2024

Right. It uses the variables in the DataFrame index. When there are two, you need a pandas multi-index.

from comp-econ-sp19.

jmbejara avatar jmbejara commented on July 18, 2024

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.

erineidschun avatar erineidschun commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.