Dear all, my problem is following. I know Stata, but currently I have to use R. Could You please help in finding the analogy to R. (1) creating of City-Dummy. I know in Stata: g byte city=0 replace city=1 if city==12&year==2000 and (2) Create a Time-Dummy-Variable g byte T2000=0 replace T2000=1 if year==2000 (3) I need the City DUmmy for the following combination: I have the financial flows between two cities in the state and I need the paired-Dummy for the exporter (state1) and importer (state2): g byte city11=0 replace city11=1 if state1==12¦state2==12 (4) I am interesting in residuals for particular city==12. I have the Dummy for City==12 and regress it on Y-Variable. How could I extract from the output in R the residulas for city==12 (1) to plot this residuals and residuals from other regions in boxplot and (2) to etsimate the confidence interval. Thanks very much in advice, Susan --------------------------------- [[alternative HTML version deleted]]
> From: Susana Bird > > Dear all, > > my problem is following. I know Stata, but currently I have > to use R.I have the opposite of your problem: I don't know Stata, but I don't have to use Stata. 8-)> Could You please help in finding the analogy to R. > > (1) creating of City-Dummy. > > I know in Stata: > > g byte city=0 > replace city=1 if city==12&year==2000 > > and > > (2) Create a Time-Dummy-Variable > > g byte T2000=0 > replace T2000=1 if year==2000Because I don't know Stata, I'm not sure what those commands do, but I'll take a crack at guessing anyway. If `year' is a vector of numbers, you can do something like: T2000 = ifelse(year == 2000, 1, 0) [Your #1 above doesn't quite make sense to me: If you initialize `city' to 0, how do you condition on city == 12? Anyway, the same idea should apply: use ifelse().]> (3) I need the City DUmmy for the following combination: I > have the financial flows between two cities in the state and > I need the paired-Dummy for the exporter (state1) and > importer (state2): > > g byte city11=0 > replace city11=1 if state1==12|state2==12Seems to me that ifelse() will work here, too.> (4) I am interesting in residuals for particular city==12. I > have the Dummy for City==12 and regress it on Y-Variable. How > could I extract from the output in R the residulas for > city==12 (1) to plot this residuals and residuals from other > regions in boxplot and (2) to etsimate the confidence interval.Something like: resid(regModel)[city==12] HTH, Andy> Thanks very much in advice, > > Susan > > > > > > > --------------------------------- > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
On Thu, 29 Apr 2004, [iso-8859-1] Susana Bird wrote:> Dear all, > my problem is following. I know Stata, but currently I have to use R. > Could You please help in finding the analogy to R. > > (1) creating of City-Dummy. > (2) Create a Time-Dummy-Variable >Andy Liaw has described how to do this, but you probably don't need to. In regression models in R, factor variables are automatically expanded to a suitable design matrix, by default a set of indicator (`dummy') variables for each category except the first. regModel <- lm( outcome~factor(city)*factor(time)) will give you indicator variables for each city and time and for the interactions. otherRegModel <- lm(outcome~factor(city)+factor(time)) is the model without interactions. -thomas
On Thursday 29 of April 2004 07:49, Susana Bird wrote:> my problem is following. I know Stata, but currently I have touse R. Could You please help in finding the analogy to R. I am too clueless about Stata, but I have another hint (check "Introduction to R" whether I have guessed correctly for what you want to do):> g byte city=0I have no clue what does it is supposed to mean (initialize city with zeroes? But how can you test for its value then?).> replace city=1 if city==12&year==2000What about this? city <- city[city == "12" & year == "2000"] Take a look at this example: > city <- cbind(rnorm(100,50,10),0) > city > city[,2] <- as.logical(city[,1]<"50") > city Does it make any sense to you? Mat??j -- Matej Cepl, http://www.ceplovi.cz/matej GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC 138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488 A modest little person, with much to be modest about. -- Winston Churchill