Cristina Cametti
2016-Jul-23 14:49 UTC
[R] country fixed effects model with binary dependent variable
Dear all, I am having problems finding a reliable code for a country fixed effects model with binary dependent variable. I was able to run it for another part of my research, because in that case the dependent variable is continuous. This is my code for the continuous dependent variable ?imwbcrm_rec?: modelfe2 <- lm(imwbcrm_rec ~ tvpol + victim + agea + gndr + eduyrs + lrscale_GM + imgfrnd_dum + qfimwht +factor(cntry)-1, data=mydata) Please don?t mind to how I wrote the variables, they are from the first wave of the ESS survey. At this point, I have three questions: - do you think this code is correct? Since the data are all from the same year (2002), I did not used the ppm package since it is only for panel data. The results of the previous code make sense, so I am satisfied. However, I want to be sure that I am running the right code. - second questions: someone knows the code for the same analysis, but having a BINARY dependent variable (aesfdrk_dummy)? I found very different information on the internet, and unfortunately, I do not know how to use STATA, so I need to find a reliable code in r. This is the code that I have now: modelfe1 <-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea+ gndr + eduyrs + domicil + partner + tvpol + hincfel_dum + factor(cntry) -1, data=mydata) -last question: I have to add some interaction between country level variables and individual level variables. So, do you think that this code is right? mydata$ppltrst_GMXprison_pop <- mydata$ppltrst_GM*mydata$prison_pop mydata$ppltrst_GMXforeign_pop <- mydata$ppltrst_GM*mydata$foreign_pop mydata$victimXprison_pop<- mydata$victim*mydata$prison_pop mydata$victimXforeign_pop<- mydata$victim*mydata$foreign_pop mydata$mixed_neighXprison_pop<- mydata$mixed_neigh*mydata$prison_pop mydata$mixed_neighXforeign_pop <- mydata$mixed_neigh*mydata$foreign_pop mydata$ethnic_neighXprison_pop <- mydata$ethnic_neigh*mydata$prison_pop mydata$ethnic_neighXforeign_pop <- mydata$ethnic_neigh*mydata$foreign_pop modelfe1.2<-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea + gndr + eduyrs + domicil + partner + tvpol + hincfel_dum + victim + ppltrst + ppltrstXprison_pop + ppltrst_Xforeign_pop_ + victimXprison_pop_ + victimXforeign_pop + mixed_neighXprison_pop + mixed_neighXforeign_pop + ethnic_neighXprison_pop + ethnic_neighXforeign_pop + factor(cntry)-1, data=mydata) Thank you very much for your attention. Kind Regards, Cristina
Rolf Turner
2016-Jul-24 00:52 UTC
[R] [FORGED] country fixed effects model with binary dependent variable
On 24/07/16 02:49, Cristina Cametti wrote:> Dear all, > > I am having problems finding a reliable code for a country fixedeffects model with binary dependent variable. I was able to run it for another part of my research, because in that case the dependent variable is continuous.> This is my code for the continuous dependent variable ?imwbcrm_rec?: > > modelfe2 <- lm(imwbcrm_rec ~ tvpol + victim + agea + gndr + eduyrs +lrscale_GM + imgfrnd_dum + qfimwht +factor(cntry)-1, data=mydata)> > Please don?t mind to how I wrote the variables, they are from thefirst wave of the ESS survey. At this point, I have three questions:> - do you think this code is correct?It is impossible to say; members of this list are not in general telepathic. You need to describe your problem and your data more clearly, or possibly supply a reproducible example, in order for anyone to have a ghost of a chance of being able to advise you.> Since the data are all from thesame year (2002), I did not used the ppm package since it is only for panel data. The results of the previous code make sense, so I am satisfied. However, I want to be sure that I am running the right code.> - second questions: someone knows the code for the same analysis, > buthaving a BINARY dependent variable (aesfdrk_dummy)? I found very different information on the internet, and unfortunately, I do not know how to use STATA, so I need to find a reliable code in r. This is the code that I have now:> > modelfe1 <-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea+ gndr > +eduyrs + domicil + partner + tvpol + hincfel_dum + factor(cntry) -1, data=mydata) It is very common to model a binary response using a logit model (i.e. use glm() with family=binomial). Whether this is appropriate in the given case is impossible to say.> -last question: I have to add some interaction between country levelvariables and individual level variables. So, do you think that this code is right?> > mydata$ppltrst_GMXprison_pop <- mydata$ppltrst_GM*mydata$prison_pop > mydata$ppltrst_GMXforeign_pop <- > mydata$ppltrst_GM*mydata$foreign_pop mydata$victimXprison_pop<- > mydata$victim*mydata$prison_pop mydata$victimXforeign_pop<- > mydata$victim*mydata$foreign_pop mydata$mixed_neighXprison_pop<- > mydata$mixed_neigh*mydata$prison_pop mydata$mixed_neighXforeign_pop > <- mydata$mixed_neigh*mydata$foreign_pop > mydata$ethnic_neighXprison_pop <- > mydata$ethnic_neigh*mydata$prison_pop mydata$ethnic_neighXforeign_pop > <- mydata$ethnic_neigh*mydata$foreign_pop > > modelfe1.2<-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea + > gndr+ eduyrs + domicil + partner + tvpol + hincfel_dum + victim + ppltrst + ppltrstXprison_pop + ppltrst_Xforeign_pop_ + victimXprison_pop_ + victimXforeign_pop + mixed_neighXprison_pop + mixed_neighXforeign_pop + ethnic_neighXprison_pop + ethnic_neighXforeign_pop + factor(cntry)-1, data=mydata) The foregoing makes no sense at all to me. Perhaps I am just being obtuse, but I doubt it. You seem to be very much out of your depth. I think you would be well-advised to seek local statistical consultation. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
David Winsemius
2016-Jul-24 04:04 UTC
[R] country fixed effects model with binary dependent variable
> On Jul 23, 2016, at 7:49 AM, Cristina Cametti <cristina.cametti at gmail.com> wrote: > > Dear all, > > I am having problems finding a reliable code for a country fixed effects model with binary dependent variable. I was able to run it for another part of my research, because in that case the dependent variable is continuous. > This is my code for the continuous dependent variable ?imwbcrm_rec?: > > modelfe2 <- lm(imwbcrm_rec ~ tvpol + victim + agea + gndr + eduyrs + lrscale_GM + imgfrnd_dum + qfimwht +factor(cntry)-1, data=mydata) > > Please don?t mind to how I wrote the variables,That is the most <bite-my-tongue> <deleted> preamble I have ever seen. How can it not be important how you constructed your covariates? .... ?????> they are from the first wave of the ESS survey. At this point, I have three questions: > - do you think this code is correct?Really? First you ask us not to question your construction of covariates, and ... THEN ask us if it is "correct"?> Since the data are all from the same year (2002), I did not used the ppm package since it is only for panel data. The results of the previous code make sense, so I am satisfied. However, I want to be sure that I am running the right code. > - second questions: someone knows the code for the same analysis, but having a BINARY dependent variable (aesfdrk_dummy)? I found very different information on the internet, and unfortunately, I do not know how to use STATA, so I need to find a reliable code in r. This is the code that I have now: > > modelfe1 <-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea+ gndr + eduyrs + domicil + partner + tvpol + hincfel_dum + factor(cntry) -1, data=mydata) > > -last question: I have to add some interaction between country level variables and individual level variables. So, do you think that this code is right? > > mydata$ppltrst_GMXprison_pop <- mydata$ppltrst_GM*mydata$prison_pop > mydata$ppltrst_GMXforeign_pop <- mydata$ppltrst_GM*mydata$foreign_pop > mydata$victimXprison_pop<- mydata$victim*mydata$prison_pop > mydata$victimXforeign_pop<- mydata$victim*mydata$foreign_pop > mydata$mixed_neighXprison_pop<- mydata$mixed_neigh*mydata$prison_pop > mydata$mixed_neighXforeign_pop <- mydata$mixed_neigh*mydata$foreign_pop > mydata$ethnic_neighXprison_pop <- mydata$ethnic_neigh*mydata$prison_pop > mydata$ethnic_neighXforeign_pop <- mydata$ethnic_neigh*mydata$foreign_pop > > modelfe1.2<-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea + gndr + eduyrs + domicil + partner + tvpol + hincfel_dum + victim + ppltrst + ppltrstXprison_pop + ppltrst_Xforeign_pop_ + victimXprison_pop_ + victimXforeign_pop + mixed_neighXprison_pop + mixed_neighXforeign_pop + ethnic_neighXprison_pop + ethnic_neighXforeign_pop + factor(cntry)-1, data=mydata) > > > Thank you very much for your attention. > Kind Regards, > > Cristina > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius Alameda, CA, USA
Jim Lemon
2016-Jul-24 04:50 UTC
[R] country fixed effects model with binary dependent variable
Hi Cristina, As Rolf has noted, you probably don't want to persist with "lm" since I think you have dichotomized your initial dependent variable. I also think that you meant "don't worry about the change of variable names" with "how I wrote the variables". I also think that you want to test interactions between the variables you are adding. _Maybe_ something like this: modelfe1.2<-glm(aesfdrk_dummy ~ agea + gndr + eduyrs + domicil + partner + tvpol + hincfel_dum + ppltrst_GM:prison_pop + ppltrst_GM:foreign_pop_ + victim*prison_pop_ + victim*foreign_pop + mixed_neigh*prison_pop + mixed_neigh*foreign_pop + ethnic_neigh*prison_pop + ethnic_neigh*foreign_pop + factor(cntry)-1, data=mydata, family="binomial") Jim On Sun, Jul 24, 2016 at 12:49 AM, Cristina Cametti <cristina.cametti at gmail.com> wrote:> Dear all, > > I am having problems finding a reliable code for a country fixed effects model with binary dependent variable. I was able to run it for another part of my research, because in that case the dependent variable is continuous. > This is my code for the continuous dependent variable ?imwbcrm_rec?: > > modelfe2 <- lm(imwbcrm_rec ~ tvpol + victim + agea + gndr + eduyrs + lrscale_GM + imgfrnd_dum + qfimwht +factor(cntry)-1, data=mydata) > > Please don?t mind to how I wrote the variables, they are from the first wave of the ESS survey. At this point, I have three questions: > - do you think this code is correct? Since the data are all from the same year (2002), I did not used the ppm package since it is only for panel data. The results of the previous code make sense, so I am satisfied. However, I want to be sure that I am running the right code. > - second questions: someone knows the code for the same analysis, but having a BINARY dependent variable (aesfdrk_dummy)? I found very different information on the internet, and unfortunately, I do not know how to use STATA, so I need to find a reliable code in r. This is the code that I have now: > > modelfe1 <-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea+ gndr + eduyrs + domicil + partner + tvpol + hincfel_dum + factor(cntry) -1, data=mydata) > > -last question: I have to add some interaction between country level variables and individual level variables. So, do you think that this code is right? > > mydata$ppltrst_GMXprison_pop <- mydata$ppltrst_GM*mydata$prison_pop > mydata$ppltrst_GMXforeign_pop <- mydata$ppltrst_GM*mydata$foreign_pop > mydata$victimXprison_pop<- mydata$victim*mydata$prison_pop > mydata$victimXforeign_pop<- mydata$victim*mydata$foreign_pop > mydata$mixed_neighXprison_pop<- mydata$mixed_neigh*mydata$prison_pop > mydata$mixed_neighXforeign_pop <- mydata$mixed_neigh*mydata$foreign_pop > mydata$ethnic_neighXprison_pop <- mydata$ethnic_neigh*mydata$prison_pop > mydata$ethnic_neighXforeign_pop <- mydata$ethnic_neigh*mydata$foreign_pop > > modelfe1.2<-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea + gndr + eduyrs + domicil + partner + tvpol + hincfel_dum + victim + ppltrst + ppltrstXprison_pop + ppltrst_Xforeign_pop_ + victimXprison_pop_ + victimXforeign_pop + mixed_neighXprison_pop + mixed_neighXforeign_pop + ethnic_neighXprison_pop + ethnic_neighXforeign_pop + factor(cntry)-1, data=mydata) > > > Thank you very much for your attention. > Kind Regards, > > Cristina > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Cristina Cametti
2016-Jul-24 09:18 UTC
[R] country fixed effects model with binary dependent variable
Dear all, thank you very much for all your answers. Probably, I don?t know how to write in this mailing list, so I apologize if I was not clear. My questions were all code related: I am not an R user, this means that I started using R just few months ago. So, I am seeking advise about the coding and that is why I was writing here. The part about not to mind how I wrote the variables meant only that the names may appear weird because I used the same in the ESS survey and in other cases, I created new names that do not make sense. So it was just a simple suggestions about my way to write the name of the variables, because the focus of my questions were others. So, I am sorry if I upset you and basically, all wrote by Jim was correct about my questions. So thank you Jim, in the meantime I was working on the code and in the end I came up with the same code as you. I used ?glm? and added ?family=binomial?. So now that I have the confirmation from an expert that this is a reliable code for my analysis, I am more sure about my results. Thank you all again for your attention. Kind Regards, Cristina Il giorno 24/lug/2016, alle ore 06:50, Jim Lemon <drjimlemon at gmail.com> ha scritto:> Hi Cristina, > As Rolf has noted, you probably don't want to persist with "lm" since > I think you have dichotomized your initial dependent variable. I also > think that you meant "don't worry about the change of variable names" > with "how I wrote the variables". I also think that you want to test > interactions between the variables you are adding. _Maybe_ something > like this: > > modelfe1.2<-glm(aesfdrk_dummy ~ agea + gndr + eduyrs + domicil + > partner + tvpol + hincfel_dum + ppltrst_GM:prison_pop + > ppltrst_GM:foreign_pop_ + victim*prison_pop_ + victim*foreign_pop + > mixed_neigh*prison_pop + mixed_neigh*foreign_pop + > ethnic_neigh*prison_pop + ethnic_neigh*foreign_pop + factor(cntry)-1, > data=mydata, family="binomial") > > Jim > > > On Sun, Jul 24, 2016 at 12:49 AM, Cristina Cametti > <cristina.cametti at gmail.com> wrote: >> Dear all, >> >> I am having problems finding a reliable code for a country fixed effects model with binary dependent variable. I was able to run it for another part of my research, because in that case the dependent variable is continuous. >> This is my code for the continuous dependent variable ?imwbcrm_rec?: >> >> modelfe2 <- lm(imwbcrm_rec ~ tvpol + victim + agea + gndr + eduyrs + lrscale_GM + imgfrnd_dum + qfimwht +factor(cntry)-1, data=mydata) >> >> Please don?t mind to how I wrote the variables, they are from the first wave of the ESS survey. At this point, I have three questions: >> - do you think this code is correct? Since the data are all from the same year (2002), I did not used the ppm package since it is only for panel data. The results of the previous code make sense, so I am satisfied. However, I want to be sure that I am running the right code. >> - second questions: someone knows the code for the same analysis, but having a BINARY dependent variable (aesfdrk_dummy)? I found very different information on the internet, and unfortunately, I do not know how to use STATA, so I need to find a reliable code in r. This is the code that I have now: >> >> modelfe1 <-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea+ gndr + eduyrs + domicil + partner + tvpol + hincfel_dum + factor(cntry) -1, data=mydata) >> >> -last question: I have to add some interaction between country level variables and individual level variables. So, do you think that this code is right? >> >> mydata$ppltrst_GMXprison_pop <- mydata$ppltrst_GM*mydata$prison_pop >> mydata$ppltrst_GMXforeign_pop <- mydata$ppltrst_GM*mydata$foreign_pop >> mydata$victimXprison_pop<- mydata$victim*mydata$prison_pop >> mydata$victimXforeign_pop<- mydata$victim*mydata$foreign_pop >> mydata$mixed_neighXprison_pop<- mydata$mixed_neigh*mydata$prison_pop >> mydata$mixed_neighXforeign_pop <- mydata$mixed_neigh*mydata$foreign_pop >> mydata$ethnic_neighXprison_pop <- mydata$ethnic_neigh*mydata$prison_pop >> mydata$ethnic_neighXforeign_pop <- mydata$ethnic_neigh*mydata$foreign_pop >> >> modelfe1.2<-lm(aesfdrk_dummy ~mixed_neigh + ethnic_neigh + agea + gndr + eduyrs + domicil + partner + tvpol + hincfel_dum + victim + ppltrst + ppltrstXprison_pop + ppltrst_Xforeign_pop_ + victimXprison_pop_ + victimXforeign_pop + mixed_neighXprison_pop + mixed_neighXforeign_pop + ethnic_neighXprison_pop + ethnic_neighXforeign_pop + factor(cntry)-1, data=mydata) >> >> >> Thank you very much for your attention. >> Kind Regards, >> >> Cristina >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code.