Re: [R] If loops?
Yes thanks guys the pmin did the trick. Primitif maybe but effective. On Fri, Nov 2, 2012 at 3:12 AM, David Winsemius [via R] < ml-node+s789695n4648205...@n4.nabble.com> wrote: > > On Nov 1, 2012, at 6:38 PM, arun wrote: > > > Hi, > > > > You can try this also : > > set.seed(132) > > > > dat1<-data.frame(Company=rep(LETTERS[1:4],c(3,4,5,6)),Last_year=sample(2005:2012,18,replace=TRUE)) > > > dat2<-dat1[order(dat1$Company,dat1$Last_year),] > > dat2$Last<-ave(dat2$Last_year,dat2$Company,FUN=function(x) > ifelse(x>=2009,2009,x)) > > None of the `ifelse` conditional or desired consequent depend on the > Company value. Just wasted CPU cycles are the result. If you choose to use > `ifelse` , then why not: > > dat2$Last2<- ifelse(dat2$Last_year > 2009, 2009, dat2$Last_year) # > the '=' also not needed > > > head(dat2) > > > > > # Company Last_year Last > > #3 A 2007 2007 > > #1 A 2010 2009 > > #2 A 2012 2009 > > #6 B 2007 2007 > > #4 B 2008 2008 > > #5 B 2008 2008 > > > > identical(dat2[,3],pmin(dat2[,2],2009)) > > #[1] TRUE > > > > identical(dat2[,4],pmin(dat2[,2],2009)) > [1] TRUE > > > A.K. > > > > > > > > - Original Message - > > From: kebrab67 <[hidden > > email]<http://user/SendEmail.jtp?type=node&node=4648205&i=0>> > > > To: [hidden email]<http://user/SendEmail.jtp?type=node&node=4648205&i=1> > > Cc: > > Sent: Thursday, November 1, 2012 8:41 PM > > Subject: [R] If loops? > > > > I have a set of data with 205 988 observation sand 10 variables , three > of > > which are Legal_status, Date_of_incorporation and Last_year. I set my > time > > horizon from 1989 to 2009. Now I want to know when a company is dead. If > > Last_year is bigger or equal to 2009 then I say that a new "variable" > last > > is 2009. If Last_year is smaller than 2009 then my new variable "last" > is > > equal to the variable "Last_year". I wanted to know how I can generate > this > > new variable and connect it to my original data called data. > > > > > > > > -- > > View this message in context: > http://r.789695.n4.nabble.com/If-loops-tp4648199.html > > Sent from the R help mailing list archive at Nabble.com. > > [[alternative HTML version deleted]] > > > > __ > > [hidden email] > > <http://user/SendEmail.jtp?type=node&node=4648205&i=2>mailing list > > 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, MD > Alameda, CA, USA > > __ > [hidden email] <http://user/SendEmail.jtp?type=node&node=4648205&i=3>mailing > list > 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. > > > -- > If you reply to this email, your message will be added to the discussion > below: > http://r.789695.n4.nabble.com/If-loops-tp4648199p4648205.html > To unsubscribe from If loops?, click > here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4648199&code=c2VsYW1nZXRhY2hld0BnbWFpbC5jb218NDY0ODE5OXwtNTU1NzM1MTAx> > . > NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > -- Selam Getachew M1 Statistiques Econometrie Responsable du Pole Communication AESES -- View this message in context: http://r.789695.n4.nabble.com/If-loops-tp4648199p4648206.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] If loops?
I have a set of data with 205 988 observation sand 10 variables , three of which are Legal_status, Date_of_incorporation and Last_year. I set my time horizon from 1989 to 2009. Now I want to know when a company is dead. If Last_year is bigger or equal to 2009 then I say that a new "variable" last is 2009. If Last_year is smaller than 2009 then my new variable "last" is equal to the variable "Last_year". I wanted to know how I can generate this new variable and connect it to my original data called data. -- View this message in context: http://r.789695.n4.nabble.com/If-loops-tp4648199.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] IV estimation
Hello, I have a set of 100 variables with 1560 observations. I did an O.L.S regression of three of these variables on a fourth. But there are problems of endogeneity... So I look in my dataset for instruments to do an IV. I can't find a good instrument because their correlation with my endogeneous variables are too low. But I see that when I create a combined variable composed of 12 variables of the dataset my correlation is much stronger. Can I use such a combined variable to estimate my equation with 2SLS, or GMM. -- View this message in context: http://r.789695.n4.nabble.com/IV-estimation-tp4599559.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] "Conditional" average
id age76 Wage76 Grade76 Black immigrt. ... 1 25 102456 12 1 0 2 27 15432 15 0 1 3 30 12340 16 1 1 Then I have lots of data variables 100 for 5000 individuals nearly. What I wanted is to discriminated by age and education level (age is years only and grade is years in educational system and wage is salary only no rational numbers here) I want to have for people of education level 10 12 16, the average wage for age 15, and then the same for age 16, and the same for age 17 and so on... Once i have these average I plot (age vs average salary) to see the "distribution in average" -- View this message in context: http://r.789695.n4.nabble.com/Conditional-average-tp4585313p4586691.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
[R] "Conditional" average
Hello, I have a set of data including age, wage and education level each called age76, wage76 and grade76 I want to know how i can calculate the average wage of people age 15 to 65 (each year separetly) , only for those who have an education level of 10 12 and 16... -- View this message in context: http://r.789695.n4.nabble.com/Conditional-average-tp4585313p4585313.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] r ols help
I see what you mean as I go trgouh my courses (chapters related to type i and II errors) Is there any way in the therory for me to choose which variables in a set of variables explain more my Y. Or should I base my reflexion solely on economic theory and discriminate between variables? -- View this message in context: http://r.789695.n4.nabble.com/R-help-tp4539571p4540292.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] r ols help
The eleventh variable is log(wage) and the 10 other variables are actually all at least theorically significant to the regression. like wether the person is black, immmigrant, it´s experience, age, if he works in a city... But i need only take a few variables out of this ten. Actually taking only experience experience² and education level is enough to make the regression significate. But i need some control parmeters added. I don´t want to choose all of them so I am trying to see which gives me an esthetic result. -- View this message in context: http://r.789695.n4.nabble.com/R-help-tp4539571p4539990.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] R help
I have a 11*1562 set of data. I want to regress using ols all combination of the ten variables on the eleventh. Store the results of the t test of each regression and the r2 to compare which combination is better. the combination can use any amount o variables. How can I do that in R? -- View this message in context: http://r.789695.n4.nabble.com/R-help-tp4539571p4539571.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.