[R] Dummies in R

Thomas Lumley tlumley at u.washington.edu
Thu Apr 29 16:08:43 CEST 2004

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

otherRegModel <- lm(outcome~factor(city)+factor(time))

is the model without interactions.


More information about the R-help mailing list