Тёмный
No video :(

Panel Data (Fixed Effects, Random Effects) - R for Economists Moderate 9 

Econometrics, Causality, and Coding with Dr. HK
Подписаться 15 тыс.
Просмотров 46 тыс.
50% 1

Опубликовано:

 

6 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 159   
@imanederrhi1530
@imanederrhi1530 3 года назад
Sir, your video saved my master's thesis. Thank you for your clear explanations!
@nathanroberts6440
@nathanroberts6440 8 месяцев назад
Two years later it is still helping with master's thesis.
@saranshgarg9350
@saranshgarg9350 3 года назад
Can't thank you enough for how awesomely you explain the R part You have covered everything that's not there in one single video anywhere else you the best
@Quickseb
@Quickseb 5 лет назад
You saved me and my bachelors degree
@dbo514
@dbo514 4 года назад
2 minutes in and this is the best produced video on econometrics on youtube. Very engaging presence and voice Graduated economics with donors 5 years ago, and still need a refresher every now and then lol Thanks for the presentation
@tahasaeed5458
@tahasaeed5458 2 года назад
This is so clear. Please keep making stats more accessible 🙏🙏🙏
@MrFMVS
@MrFMVS Год назад
Just found my new favorite channel. Thank you for these videos.
@abelorrego3243
@abelorrego3243 4 года назад
Thanks for this video professor! You explain better than anyone!
@programacaosimples
@programacaosimples 4 года назад
Thank you, Nick! Greetings from Brazil!
@adamw2030
@adamw2030 3 года назад
So helpful. Was forgetting to declare it as a panel data frame!
@adeelkhan800
@adeelkhan800 3 года назад
Great video! Very well explained. Thanks for this.
@kilianelfert3552
@kilianelfert3552 2 года назад
Thank you so much! Very informative & easy to follow.
@TinaTina-xn9on
@TinaTina-xn9on Год назад
Thank you for your amazing effort. There is a big issue in panel data which is the cross-sectional dependence besides the autocorrelation and heteroskedasticity. It would be great if you add a supplementary video of vcovHC, vcovSCC... etc
@jessesutton7460
@jessesutton7460 2 года назад
Thank you so much. This was very informative.
@shankarjeetpanda3476
@shankarjeetpanda3476 3 месяца назад
Literally saved me. Ur a legend ❤
@javierbeltran7623
@javierbeltran7623 5 лет назад
Thanks for the video!!!!...I will give it a look ASAP!!!!...Cheers!!!
@nasimaakter4164
@nasimaakter4164 4 года назад
Thanks a lot for the video!!! I really need the basics, even during my Master degree.
@michaelkyrie6836
@michaelkyrie6836 3 года назад
i know Im asking randomly but does someone know a way to log back into an Instagram account..? I was dumb lost my login password. I would appreciate any help you can offer me!
@bentleealessandro2078
@bentleealessandro2078 3 года назад
@Michael Kyrie instablaster :)
@michaelkyrie6836
@michaelkyrie6836 3 года назад
@Bentlee Alessandro I really appreciate your reply. I found the site through google and Im trying it out atm. Seems to take a while so I will reply here later with my results.
@michaelkyrie6836
@michaelkyrie6836 3 года назад
@Bentlee Alessandro it did the trick and I actually got access to my account again. Im so happy:D Thank you so much you saved my account!
@bentleealessandro2078
@bentleealessandro2078 3 года назад
@Michael Kyrie You are welcome :D
@agatawidomska562
@agatawidomska562 4 года назад
Thank you very much Sir! Very helpful :)
@almaarmenta4779
@almaarmenta4779 5 месяцев назад
Thank you for this! I always get confused between the graph for random intercept and fixed effects
@sofiagrafa6711
@sofiagrafa6711 3 года назад
Best background topic ever !!!
@bjoernaagaard
@bjoernaagaard 5 лет назад
Good shit man. Really enjoyed this.
@nikhilmuthukrishnan7222
@nikhilmuthukrishnan7222 2 года назад
Love your board games collection.....
@JonesDawg
@JonesDawg 3 года назад
Thank you very much!
@senzeybek9497
@senzeybek9497 5 лет назад
Professor thank you a lot for the video. It is really hard to find something easy to understand about this topic, and this video makes so many things clear for me. I have a question about the video. In plm function we can choose (model="within", effect='"time") and (model="between"). As I understand from your between model definition, I would expect to have the same results, but my results are different than each other. My question is that what is the difference between time effect within model and between model?
@clairinsrim2980
@clairinsrim2980 4 года назад
Thanks, it is very helpful! Is there also some video/some documents we can check to understand how to run VIF, partial F test and VAR method for panel data? Thank you
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
I'm afraid I don't have materials on those except or partial F (see my post regression statistics video), but for vif I recommend the jtools package. Never done a VAR in R myself I'm afraid
@hannahsalamon7697
@hannahsalamon7697 4 года назад
Hi Nick, thanks so much for this video, it's incredibly helpful! Just a quick question-- I want to lag an independent variable by more than just one period before. Do you know how to code for lags of 2,3,4,etc. periods?
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
In plm, lag(x, 2) will lag 2 periods for example
@ninic1682
@ninic1682 Год назад
Thank you so much for the clear explanation. What are reasons to prefer fixed effects model over random ones in theory?
@NickHuntingtonKlein
@NickHuntingtonKlein Год назад
Thanks! I'd recommend checking out this section of my fixed effects chapter www.theeffectbook.net/ch-FixedEffects.html#random-effects
@doron105
@doron105 4 года назад
Hi, Thanks for the videos! quick question: I noticed that when using the plm function, the R-squared statistic is not including the variation explained by the time and space fixed effects variables. Is there a way to include it into the results? I tried doing it with lm() and inserting the year and space variables (as factors) but i have too many spaces (34,000) and I recieve an error that "cannot allocate a vector of size 8.4 GB". Thanks again!
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
I don't think plm can do it directly but you can compute it by hand as in karthur.org/2016/fixed-effects-panel-models-in-r.html Or, estimate it instead in lfe (see the same link) or estimatr (see my estimatr video) which report the full R squarws
@oliversinho6762
@oliversinho6762 3 года назад
Hi Nick, thanks for the great content! I have one question: I am a step before this video. Therefore, still trying to figure out what to do with my missing data. It's not a lot that is missing though some of it is in the dependent variable and some of it in the independent variable. Do you have any videos on that? Would be very grateful for any advice here! Best Oliver
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
I'm afraid I don't have any videos on missing data. The standard thing to do is just to drop observations with missing data, although that introduces a fair number of problems. You may want to look into multiple imputation.
@kevinhurzeler9705
@kevinhurzeler9705 3 года назад
Thank you for the very nice explanation! It's rare to come accross someone that can explain a topic in such a short and precise manner. I have one question though: How would you deal with unbalanced panel data ie. when number of years is different among individuals? Can you just use the same approach or fo you need to adjust for the differnces? Thx again!
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
Thank you very much! There are some small differences in methods (often computational differences as opposed to statistical differences) when it comes to unbalanced panel data. However, conveniently, most main-line panel data software is designed to handle it already, plm being an example of a package that does so. So you can use the same commands with rare exception.
@kevinhurzeler9705
@kevinhurzeler9705 3 года назад
@@NickHuntingtonKlein Thx so much!
@camiloacosta9741
@camiloacosta9741 4 года назад
HI Nick. Thanks for the video. Im running both the within and fd models. In theory, the coefficient from these two models should be the same. However, when I run the regressions, I am obtaining different coefficients. Do you know anything about this? Thanks again
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
Yes, that should be true as long as you have exactly two time periods. In plm I'm getting numerically identical results for effect = "twoways" but not effect = "individual". i.e. you add in a time period dummy to the within model and it works. That lines up with what I get using regular lm() on demeaned data. I haven't thought about that equivalence in a while so I can't remember if a time dummy is a part of it, but that's what I'm getting.
@tomenthoven3406
@tomenthoven3406 4 года назад
Hi Nick, thanks for the video, it has been really helpful! I have a question about adding the lagged dependent variable to the fixed effects model. I want to estimate a dynamic model but I read that adding the lagged dependent to the fixed effect model would give dynamic panel bias, as the correlation between the lagged variable and the error term yields inconsistent estimates. I also read that the system GMM estimator developed for dynamic models deals with this issue. What do you think about this and do you know how to code the system GMM estimator in R?
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
I've never done it myself, but I believe the package to do it in is pgmm
@tomenthoven3406
@tomenthoven3406 4 года назад
@@NickHuntingtonKlein Alright thank you, I'll have a look!
@rajat1770
@rajat1770 3 года назад
@nick Thank you professor for a very informative and clear explanation. I have one question, do we need to add the dummy variable for Year in the plm model? fixedeff
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
If you want to add year effects you're better off by specifying it as a two-way model in the options
@rajat1770
@rajat1770 3 года назад
@@NickHuntingtonKlein can you please point me in the right direction. I didn't get you, what do you mean by two way model
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
@@rajat1770 A two way fixed effects model is a regression model with fixed effects for individual/group and also fixed effects for time. You can get this in plm using effect = "twoways" as long as you specify both a group and time variable for the index
@richardkonig4514
@richardkonig4514 5 лет назад
Hey Nick, Thanks for the explanation. Do you know how to check for multicollinearity in panal data regressions?
@NickHuntingtonKlein
@NickHuntingtonKlein 5 лет назад
Glad it helped! The standard test is the variance inflation factor or VIF. I don't know the R command off the top of my head but there's your Google term.
@richardkonig4514
@richardkonig4514 5 лет назад
@@NickHuntingtonKlein Thanks for replying so quickly. The VIF commands only seem to work for lm not plm commands. Anyway, thanks for taking the time, it's much appreciated.
@DanChoiThon
@DanChoiThon 2 года назад
Thank you so much, professor! Such high-quality content! I have three questions regarding the fixed effect model which you did. - Is that ONLY "county" fixed effect? How do I include "time" fixed effect into that model? In this case, the "year" variable? I want to do both country AND year fixed effects. - The lag function that you used, is it by default 1 year (1 row) lag? Don't we need to specify how much lag we want? - How do I increase the lag, let say 2 years in this case? Thank you and best regards!
@NickHuntingtonKlein
@NickHuntingtonKlein 2 года назад
For all of these I'd recommend checking out my video on the fixest package, which makes two way fixed effects easy and has an easily customizable lag function
@DanChoiThon
@DanChoiThon 2 года назад
@@NickHuntingtonKlein Thank you, sir!
@oguz6601
@oguz6601 11 месяцев назад
Dear Professor, do you have any video related to BLPEstimator in R or any step-by-step guide as in your knowledge? I'm trying to use it for my paper but I am super confused. Thank you, your videos are extremely helpful!
@NickHuntingtonKlein
@NickHuntingtonKlein 11 месяцев назад
Thanks! I'm afraid I don't have any blp materials though.
@hannahsalamon7697
@hannahsalamon7697 3 года назад
Hi there-- do you have any suggestions for specific packages/code to use for visualizing panel data regressions in R? I'm having a hard time finding any guidance!
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
Depends what kind of visualization you want! jtools has some good regression visualizations. I've also been largely using fixest for fixed effects these days, and it has its own set of regression visualization functions
@prafullakumarnath5431
@prafullakumarnath5431 4 года назад
Hi...as always your delivery is unparallel. I have one question: can one try fixed effect model for a pseudo panel data (multiple cross sectional data pooled together)? each time data collected from a new sample. Stata declares it as weakly balanced data. Any suggestion is appreciated.
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
I'd call that a repeated cross section. You can add some sorts of fixed effects to that (like time) but not others (like individual). If plm won't let you register it as a pdata.frame, check out my estimatr video
@angeldejesuscastillonegret2318
@angeldejesuscastillonegret2318 2 года назад
Hey, does anyone know if there's a way to perform a two-way clustered standard errors when working with plm package ? So far I haven't been able to solve this issue, ever since coeftest only allows one to cluster either by individual or by time. Thanks in advance !
@NickHuntingtonKlein
@NickHuntingtonKlein 2 года назад
The vcovDC() function in plm should be able to do it. But also you could switch to using the fixest package instead which has easy syntax for doing this.
@fifo3951
@fifo3951 2 года назад
good video! i have a question regarding FE model. I have a big issue with cross sector independence and can not "fix" it with the coeftest. i have tried both measures (vcovHC with cluster=time and driscoll and kraay) the result after running the coeftests are that all my variables are insignificant. That my means the model is not useful? what can i do?
@NickHuntingtonKlein
@NickHuntingtonKlein 2 года назад
Insignificant results doesn't mean the model is wrong, it just means your results are insignificant! That said, FE does suck a lot of the statistical power out of a model, especially if you have a "big-N-small-T" model (i.e. many groups but few observations per group). If you're pretty certain that your predictors *should* be predicting a large share of the within-variance but you're not getting anything, consider if maybe you are actually controlling away more variation than you intend. Ask: after removing the variation from the fixed effects, should there be enough variation left to actually study? You might also try random effects if you think those assumptions might be likely to hold.
@ChuvakinVlad
@ChuvakinVlad 3 года назад
Thanks vary much for posting this video. I have several questions out of it: First, can we include dummy variables in panel regression (the only thing i have found is that inappropriate for FE model, but what about other models (RE, OLS)). Second, does these assumptions works with pglm package in r studio? (When i want to run panel ordinal logistic regression (OLS, FE, RE) or panel ordinal probit regression (OLS, FE, RE)? In pglm would be interpretation the same if i will log independent variables? (like increase in 1% of log value result in increase of dependent variable on 1, because i have taken a log)
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
Including dummy variables in panel regression is totally fine (just be careful that they don't overlap too much with your fixed effects). The meaning of FE is slightly different in logit-FE or probit-FE than in OLS-FE, but the same general ideas work. The interpretation of the coefficients will be the same as in *logit or probit* models, not the same as in OLS-FE. I should point out that the "1% in log value" interpretation is for use with logged variables, not with logit/probit - those are different.
@impieman10
@impieman10 3 года назад
Hi Nick, this video is amazing! It is really saving me. I have some question regarding using the within function though. I set my indexes within the plm() regression, and there I have specified both the individual fixed effect, and the time fixed effect. Is that a correct way of doing it? Or am I losing information that way? I saw another video that includes dummies for the years, and only specifies the individual fixed effects in the index. Does that yield the same results? Lastly, if there are na's in the panel data, and I use na.action = na.omit, does this damage the results of the regression too badly? Sorry if these are too many questions at once, I'm just trying to wrap my head around the subject.
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
Yes, specifying it within plm() is the way to go - this should produce the same results as including year as a set of dummies, except perhaps for any standard error adjustments, and in that case the version with both included (and 'twoway' fixed effects specified) would be preferred. As for the NAs, if there are NAs in the data, plm will be dropping them anyway. How much damage this does to the results depends on how much data is missing and why. See the section on missing data in the Under the Rug chapter in my book nickchk.com/causalitybook.html
@impieman10
@impieman10 3 года назад
@@NickHuntingtonKlein Thank you so much Nick!
@felipealvarado4390
@felipealvarado4390 2 года назад
Hi Nick, thank you for the video, I have a question, which would be the code if i want to add fixed year effect and fixed state effect using first difference as model? I don't know how to do it. Thank a lot!
@NickHuntingtonKlein
@NickHuntingtonKlein 2 года назад
I'd recommend checking out my video on fixest, that package makes this fairly easy
@kwizeralambert1316
@kwizeralambert1316 Год назад
This is great. I like your passion, and commitment to teaching. I was wondering if you may do the videos on exploratory data analysis with R or Stata or Python, through Economics lens. Since before diving into data analysis, one has to check normality [Normal Distribution], outliers...and other issues in data that may affect analysis to avoid wrong conclusisons.
@NickHuntingtonKlein
@NickHuntingtonKlein Год назад
I do have some videos on EDA in my Data communications series
@kwizeralambert1316
@kwizeralambert1316 Год назад
@@NickHuntingtonKlein Great. Would you mind to share the link for those videos on EDA? By the way, I like to read Economics papers from top Economics Journals such as AEA, QJE..NBER, when I see they are written, analyzed, do they use Rmarkdown, Quarto, Stata Markdown..LaTex or Overleaf? What is the typingsetting system recommended for Economists with the mind of reproducibility and replication? Thanks.
@NickHuntingtonKlein
@NickHuntingtonKlein Год назад
@@kwizeralambert1316 apologies, looks like I added the EDA section to that class after making those videos. But you can see the updated course, including the EDA lecture, here github.com/nickch-k/datacommslides Most economists use either latex or Word. Markdown is slowly gaining popularity.
@kwizeralambert1316
@kwizeralambert1316 Год назад
@@NickHuntingtonKlein Thank you so much, Very rich courses. I understand, LaTex is widely used. Currently, I see some some researchers are using Quarto and Rmarkdown to write their papers
@NickHuntingtonKlein
@NickHuntingtonKlein Год назад
@@kwizeralambert1316 yes I'm pretty much exclusively using quarto from here on out, outside of collaboration with people who don't use it
@joseluissola8941
@joseluissola8941 2 года назад
Hi Nick, first of all thank you so much for this stunning video. I am a little bit confused about using Random effects with Robust standard error (sandwich estimator) in r. In Stata I use xtreg Y X, re vce(robust). How do you apply this syntax in r ?
@NickHuntingtonKlein
@NickHuntingtonKlein 2 года назад
Try running some lmer output (from lme4) through coeftest from the sandwich package, or just send it to msummary (in the modelsummary package) and set the SE type with the vcov option.
@joseluissola8941
@joseluissola8941 2 года назад
@@NickHuntingtonKleinThanks! btw, What is the difference between this RE (Robust SE) from RE in your video ?
@NickHuntingtonKlein
@NickHuntingtonKlein 2 года назад
@@joseluissola8941 RE means random effects, not Robust se. So they're different things entirely
@macro_finance
@macro_finance 4 года назад
Thank you Nick for this video. I would like to ask what would be the command in Stata equivalent to R command concerning fixed effect estimator with lag? Or any other estimator, random..?
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
After using xtset to declare the panel structure, use xtreg to run fixed or random effects. Use L. In front of a variable to lag it.
@macro_finance
@macro_finance 4 года назад
@@NickHuntingtonKlein Could you please advise, how to generate 1lag dependent variable (as you have it in your video)? I tried with slide command, and setDF command, ...etc... and nothing really works... additional problem is that I have some missing values...
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
@@macro_finance in stata? Just use L. on the dependent variable. Or if you're back in R, plm::lag should do it
@macro_finance
@macro_finance 4 года назад
@@NickHuntingtonKlein No, sorry, it is in R. Actually, whenever I run the fixed effect estimator test in R, I get the error message: Error in class(x)
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
@@macro_finance did you use pdata.frame before running fixed effects, like in the video?
@pedrozarate4566
@pedrozarate4566 4 года назад
if i want to know the time effect and country effect, in my dependant variables(GDS,GDP,GCP) with T=20 and N 20. the question ¿ shoud i have to use year dummy and country dummys ? to capture their efect in (GDS,GDP,GCP) ? and in that case wich model recomend i want to know the individuals effect and the time effect
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
If you want both effects, then yes you'd want to include fixed effects for both
@pedrozarate4566
@pedrozarate4566 4 года назад
@@NickHuntingtonKlein thanks you for the video and the quick answer (nice and complete)
@onigiriman
@onigiriman 4 года назад
very interesting, I am trying to determine if I should use FE or RE for my logit regression in R. will these model="within" commands also work with the glm lines of code ? thank!
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
That won't work. Fixed effects for logit work very differently than for linear models. Check out the bife package for fixed effects logit. I haven't used it myself but I hear good things.
@onigiriman
@onigiriman 4 года назад
@@NickHuntingtonKlein Thank you, I will look into how to use that package! I have been having trouble finding information on how to determine weather I should be using a FE model or RE model for my logistic regression. Is the Hausman test the best tool to use when making this determination?
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
@@onigiriman Hausman is designed for linear models, so that wouldn't work, unless there's some special logit version. I'm afraid I don't know too much about logit random effects.
@onigiriman
@onigiriman 4 года назад
@@NickHuntingtonKlein I see, thank you so much for your replies. They are very helpful!
@azharbz2717
@azharbz2717 4 года назад
I'm getting this msg when i'm trying to estimat fixed model error in class(x)
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
I'm afraid I don't know French, but it sounds like an internal problem with plm maybe? I'd recommend asking on StackExchange.
@Coolshoots09
@Coolshoots09 4 года назад
sir , if you could tell me how to convert country names to country id in r for a panel analysis
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
as.factor() will turn country name into a factor variable, which will be acceptable for use with plm (and other panel packages) as an id variable
@LearnArabic287
@LearnArabic287 3 года назад
First thank you for your amazing video and seconed : i ‘d like to know , i did pannel regression on stata “ want to see the effect of transport cost with other ind variables on exports in Sub Saharan Africa. ” i did regress simply and i do not know what is fixed or any thing can you please write down any advices,, thanks inadvance
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
For Stata I'd recommend looking into their panel commands. xtset lets it know you're working with panel data, and then you can do fixed effects with xtreg
@LearnArabic287
@LearnArabic287 3 года назад
@@NickHuntingtonKlein thank you professor for your interest . either not professional but I feel like crashing with my model but I really thankful to your reply.
@lanaschludi5466
@lanaschludi5466 3 года назад
Hi! I'm using panel data with the indices "firm" and "year". I tried to run a Fixed Effects regression and put "Industry" and "Year" as indices for fixed effects, but the output for FE "individual" was still firms, not industries. I heard that Industry FE are not possible in the FE model because Industry is a time-invariant variable. That's why I chose a pooled OLS model now. However, how can I determine fixed effects here? Simply as a control variable or is there any other possibility? Thank you for your help!
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
It's correct that you can't add industry as a control when you already have firm fixed effects, since they'd be perfectly collinear. The good news is you don't need to! Including firm fixed effects automatically controls for anything that's fixed within firm, like industry. So you don't need to add the industry controls, that job is already done by the firm fixed effects. If your goal is to study the effect of industry itself, are you sure you really want to control for firm? What identification problem does that solve for you? If you do really want both you'll need to run some sort of hierarchical random effects model, which can get tricky. The relevant R package for that would be lmer.
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
@@lanaschludi5466 if it says they did industry and year fixed effects then they probably didn't do firm fixed effects, just industry and year. The "yes" in the table just means "yes, we included these fixed effects, but the estimates for them aren't important so we're not going to show them to you, we just included them as controls." so you can ignore firm FE and just do industry and year.
@godwinezekoye211
@godwinezekoye211 2 года назад
Thanks for the video. How can I declare as a panel data given monthly?
@NickHuntingtonKlein
@NickHuntingtonKlein 2 года назад
In plm it should just work automatically. It assumes that the levels of the time variable it finds in the original data are consecutive and ascending.
@godwinezekoye211
@godwinezekoye211 2 года назад
@@NickHuntingtonKlein Thanks a lot for the feedback. I have tried adjust my index variable, however, I have the error: "In pdata.frame(Data) : duplicate couples (id-time) in resulting pdata.frame to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")."
@NickHuntingtonKlein
@NickHuntingtonKlein 2 года назад
@@godwinezekoye211 sounds like you have duplicates. Did you run the check it said? Plm won't work if you have multiple observations per id/time. If you want that (and are just planning to do time FEs, obviously lags won't work in this setup), switch from plm to fixest, see my fixest video.
@abelorrego3243
@abelorrego3243 4 года назад
Proffesor, do you know how one could calculate fixed effects in cross-sectional data ?
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
You have to have multiple observations of each of the things you have fixed effects of. So you can't have individual-level fixed effects in cross-sectional data. You could have fixed effects for some higher-level grouping. So for example if you had a cross-sectional data set of people, you can't have fixed effects for people, but you can have fixed effects for, say, city, as long as multiple people in your data are in each city. To do this in R, just add +factor(city) to your regression model, where city is the variable you want to add fixed effects of.
@mohammadrezaei2912
@mohammadrezaei2912 2 года назад
Tanks
@HojoJr
@HojoJr 4 года назад
Is anybody getting an issue with the index function? I get the following error; data.p=pdata.frame(data,index=c("Site","Year")) Warning message: In pdata.frame(data, index = c("Site", "Year")) : duplicate couples (id-time) in resulting pdata.frame to find out which, use e.g. table(index(your_pdataframe), useNA = "ifany")
@nafisaahmad3658
@nafisaahmad3658 3 года назад
same problem. how did u fix it?
@samj-w1196
@samj-w1196 4 года назад
Isn't it a better example of reverse causality rather than OVB? police per capita is actually based on crime rate not vice versa?
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
Depends on how crime rate is defined. Old crime rates determine current police presence which determines current crime rate. So with the variables in the data, you can consider "lagged crime rate" to be an omitted variable. But yes your interpretation makes sense too.
@rutgervanbasten2159
@rutgervanbasten2159 Год назад
Hi, mayby a wierd question but can i email you with a specific question about which model i should use for my thesis. I am really strugling :)
@NickHuntingtonKlein
@NickHuntingtonKlein Год назад
Sure, if it's brief
@rutgervanbasten2159
@rutgervanbasten2159 Год назад
thankyou! I have purchase panel data of consumers over a period of time (1.5 year). Within this period of time there is an intervention of +/ - 0.2 years implemented. this purchase data consist out of the purchase of products. These products can belong to a productgroup (in total 10 productsgroups) I am interested in the effect of the intervention on the sales of the product for each category (and compare them?). Furthermore, i do have some interaction variables with the intervention variable, so i can analyze what the effect of these variables is during such intervention As i have panel data for each invidual it is the most powerfull to determine this effect at an invidual level. However, i am not sure how to determine if i should use a fixed, a random or mixed model. Can someone give me suggestions/advice how to approach this?
@NickHuntingtonKlein
@NickHuntingtonKlein Год назад
@@rutgervanbasten2159 In your case, since you're interested in how the effect varies over different predictors, I might recommend a mixed model, and specifically an HLM where you model the effect of the intervention as a function of your predictors.
@nafisaahmad3658
@nafisaahmad3658 3 года назад
I am working with a different panel dataset and following your tutorial. When declaring my dataset as panel i ran into an error --> In pdata.frame(Healthcare, index = c("country", "Year")) : duplicate couples (id-time) in resulting pdata.frame to find out which, use e.g. table(index(your_pdataframe), useNA = "ifany") When applying fixed effects i ran in errors --> Error in `.rowNamesDF
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
It's hard to say too much without knowing your data, but it sounds like you have multiple observations per combination of country/year, which plm doesn't like. I'd recommend checking out my video on the estimatr package and using that instead.
@isaiahgangadeen3802
@isaiahgangadeen3802 4 года назад
Hi could you show how to do the Hausman Taylor model
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
See this page on how to use the pht function, or how to run H-T in plm: rdrr.io/cran/plm/man/pht.html
@isaiahgangadeen3802
@isaiahgangadeen3802 4 года назад
@@NickHuntingtonKlein thank you. I was trying to understand how they did the classification of the variables with such a simplified command but I found it explained better in another site.
@christina-4287
@christina-4287 3 года назад
hello Nick, I downloaded your r code for this video and I tried run all of your codes. however, the lagged models gave different results. The observations are not drop to 540 (as your video shown), but drop only to 639 observations. Do u know what is the reason behind it or what should I do? thank you very much...
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
The 540 is only for the first-differencing model, since it by necessity has to drop one of the time periods. Is that the one you're running?
@christina-4287
@christina-4287 3 года назад
@@NickHuntingtonKlein no sir , I runned the ( #include a lag ) model and from this ideo, it became 540 , while in my rstudio its 629. Apparently, I found the problem sir. When I load dplyr package, my result for the # include a lag model is N = 629. Once I unloaded dplyr and run it again, it becomes 540 (probably from 630- 90 county) like your video. However, i don't know why dplyr could do this 😂
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
@@christina-4287 oh, yeah, one of the downsides of dplyr is that it shares function names with a lot of other functions, so sometimes loading it will overwrite a necessary function you need
@christina-4287
@christina-4287 3 года назад
@@NickHuntingtonKlein okayy so is it better to unload the dplyr in this case 👍. Moreover sir, I tried to implement it to my data. I already unload the dplyr, and i have an original N= 1187. But when i regressed it using the lag of Y, the N drop very drastically to N = 836. But my county only 68 firms. I thought it should be 1187 - 68 only but it's not... There is also no missing value.. so why do you think R exclude many obsv in the regressiion? Thank you 🙏
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
​@@christina-4287 You don't necessarily hav eto unload dplyr, but you want to be sure to use the plm version of lag() so instead of lag() you can just say plm::lag(). As for the data dropping rapidly, are there perhaps gaps in the data? If you have time periods 1, 3, 4, 5, then applying a lag will drop both 1 and 3.
@dolcequervielle8873
@dolcequervielle8873 3 года назад
Thank you very much for this video ; it's clear ! I'm a biologist and I have to use those panel data models for my work. Do you know where I could find a clear explication on the output of summary(plm) please ? I have to report my results but untill now, I don't fully understand them :s Thank you very much!
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
Glad you like it! I'm afraid I don't know a good explainer for this. My best bet would be to just Google each term you're unfamiliar with
@dolcequervielle8873
@dolcequervielle8873 3 года назад
@@NickHuntingtonKlein ... Well ok :'( thank you very much for your quick answer. I gonna work!
@YOUKAK100
@YOUKAK100 4 года назад
what is a natural experiment
@NickHuntingtonKlein
@NickHuntingtonKlein 4 года назад
A natural experiment is when you find a source of close-to-exogenous (randomized) variation in the real world without a researcher running the experiment themselves. For example, the US Vietnam draft lottery was administered by randomly ordering birthdates. So your likelihood of being drafted into the military was random, and that could be used as a sort of experiment to look at the effects of being in the military on later outcomes.
@mulle171
@mulle171 3 года назад
where is this help file mentioned at 10:13
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
For any R function you can get the help file with help(). So in this case, help(lag). You'll want to select the one titled "lag a time series"
@mulle171
@mulle171 3 года назад
@@NickHuntingtonKlein ok, so if i want a secon lag in my plm, than i type plm(y= lag(y,k=2) +x...)
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
@@mulle171 correct, that will give you a two period lag. If you want both one and two period lags you'll need two separate lag functions though
@mulle171
@mulle171 3 года назад
amazing :D is there also a way to optimize the amount of lags ? i would have thought maybe up to the point where the variables are significant but the r^2 is as low as possible
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
@@mulle171 Typically you would try a bunch of different lag lengths and select the one that gives the best AIC or BIC statistic (Aikake/Bayesian Information Criterion). In general you pretty much never want to use statistical significance to make decisions about your model.
@mariaaguilera1414
@mariaaguilera1414 3 года назад
HI! Thank you very much!! Very useful. One question, how would you work with unbalanced panel data?
@NickHuntingtonKlein
@NickHuntingtonKlein 3 года назад
Usually the same software tools work; the necessary adjustments for unbalanced panels are often automatic and included. Check the documentation of your command of choice though
@mariaaguilera1414
@mariaaguilera1414 3 года назад
@@NickHuntingtonKlein I think the problem is there duplicate firm-year ids but I always eliminate the duplicates. I matched my outomce variable with a different firm identifier.. could it be that?
@genarahmmahato2636
@genarahmmahato2636 5 лет назад
Please show your computer screen when you are explaining rather than showing yourself.
@juanpabloaguirre6390
@juanpabloaguirre6390 5 лет назад
No, it is actually better the way he is doing it, gives a lecture feel to the video and makes it more engaging. Thanks for the great content Nick!
@barovierkevinallybose1040
@barovierkevinallybose1040 4 года назад
@@juanpabloaguirre6390 It's actually very distracting and annoying. Guess we all learn differently
Далее
Missing Data - R for Economists Moderate 10
12:52
Просмотров 1,7 тыс.
Econometrics - Within Variation and Fixed Effects
20:06
PORTAL SPAMMER🤬🤬🤬| Doge Gaming
00:19
Просмотров 2 млн
Causality: Difference-in-Differences
11:10
Просмотров 9 тыс.
Fixed and random effects with Tom Reader
8:09
Просмотров 187 тыс.
Causality: Fixed Effects
5:52
Просмотров 19 тыс.
Panel Data and Fixed Effects in R
13:05
Просмотров 69 тыс.
Econometrics - Difference in Differences
16:29
Просмотров 13 тыс.
What Language Should You Use for Econometrics?
20:51
Просмотров 3,9 тыс.
What is Expected of You as a College Student
11:52
Просмотров 1,4 тыс.