# Re: [R] Dummy variables model

From: Jean Eid <jeaneid_at_chass.utoronto.ca>
Date: Tue 06 Sep 2005 - 01:30:31 EST

here's an example

data(iris)
iris1<-iris
iris1\$setosa<-0
iris1[iris1\$Species%in%"setosa", "setosa"]<-1 iris1\$versicolor<-0
iris1\$virginica<-0
iris1[iris1\$Species%in%"virginica", "virginica"]<-1 iris1[iris1\$Species%in%"versicolor", "versicolor"]<-1 iris1<-iris1[, !colnames(iris1)%in%"Species"] summary(lm(Sepal.Length~.-1, data=iris1))

Call:
lm(formula = Sepal.Length ~ . - 1, data = iris1)

Residuals:

Min 1Q Median 3Q Max -0.794236 -0.218743 0.008987 0.202546 0.731034

Coefficients:

Estimate Std. Error t value Pr(>|t|)

```Sepal.Width   0.49589    0.08607   5.761 4.87e-08 ***
Petal.Length  0.82924    0.06853  12.101  < 2e-16 ***
Petal.Width  -0.31516    0.15120  -2.084  0.03889 *
setosa        2.17127    0.27979   7.760 1.43e-12 ***
versicolor    1.44770    0.28149   5.143 8.68e-07 ***
virginica     1.14777    0.35356   3.246  0.00145 **
```
```---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.3068 on 144 degrees of freedom
Multiple R-Squared: 0.9974,     Adjusted R-squared: 0.9973
F-statistic:  9224 on 6 and 144 DF,  p-value: < 2.2e-16

summary(lm(Sepal.Length~.-1, data=iris))

Call:
lm(formula = Sepal.Length ~ . - 1, data = iris)

Residuals:
Min        1Q    Median        3Q       Max
-0.794236 -0.218743  0.008987  0.202546  0.731034

Coefficients:
Estimate Std. Error t value Pr(>|t|)
Sepal.Width        0.49589    0.08607   5.761 4.87e-08 ***
Petal.Length       0.82924    0.06853  12.101  < 2e-16 ***
Petal.Width       -0.31516    0.15120  -2.084  0.03889 *
Speciessetosa      2.17127    0.27979   7.760 1.43e-12 ***
Speciesversicolor  1.44770    0.28149   5.143 8.68e-07 ***
Speciesvirginica   1.14777    0.35356   3.246  0.00145 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.3068 on 144 degrees of freedom
Multiple R-Squared: 0.9974,     Adjusted R-squared: 0.9973
F-statistic:  9224 on 6 and 144 DF,  p-value: < 2.2e-16

On Mon, 5 Sep 2005, Tobias Muhlhofer wrote:

> So are you guys saying to me that if I have variable firm which is the

> factor of all firm identifiers, I could just go
>
> lm(y ~ x + firm)
>
> and that will implicitly include a dummy for each level of factor firm,
> thus making this a fixed effects (aka LSDV) model?
>
> T
>
>
> Jean Eid wrote:
> > You can turn the identity vector of the firms into a factor and do lm ....
> >
> > Jean
> >
> > On Mon, 5 Sep 2005, Tobias Muhlhofer wrote:
> >
> >
> >>Hi, all!
> >>
> >>Anyone know an easy way to specify the following model.
> >>
> >>Panel dataset, with stock through time, by firm.
> >>
> >>I want to run a model of y on a bunch of explanatory variables, and one
> >>dummy for each firm, which is 1 for observations that come from firm i,
> >>and 0 everywhere else. I have over 200 firms (and a factor variable that
> >>  contains a firm identifier).
> >>
> >>dummies? I checked lme() with random = ~ 1|firm, but the problem is that
> >>these are random effects, i.e. that there are firm-by-firm disturbance
> >>terms and overall disturbance terms, whereas I want just overall
> >>disturbance terms. This is generally called a "fixed effects" model,
> >>although it seems like the term "fixed effects" is being used somewhat
> >>differently in the context of the nlme package.
> >>
> >>Toby
> >>
> >>--
> >>**************************************************************************
> >>When Thomas Edison invented the light bulb he tried over 2000
> >>experiments before he got it to work. A young reporter asked
> >>him how it felt to have failed so many times. He said
> >>"I never failed once. I invented the light bulb.
> >>It just happened to be a 2000-step process."
> >>
> >>______________________________________________
> >>R-help@stat.math.ethz.ch mailing list
> >>https://stat.ethz.ch/mailman/listinfo/r-help
> >>
> >
> >
> >
>
> --
> **************************************************************************
> When Thomas Edison invented the light bulb he tried over 2000
> experiments before he got it to work. A young reporter asked
> him how it felt to have failed so many times. He said
> "I never failed once. I invented the light bulb.
> It just happened to be a 2000-step process."
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help