[R] Dummies in R

Liaw, Andy andy_liaw at merck.com
Thu Apr 29 15:25:35 CEST 2004


> 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==2000

Because 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==12

Seems 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
> 
>




More information about the R-help mailing list