Quantcast
Channel: Noodling in the data stream
Viewing all articles
Browse latest Browse all 48

Factors in Stata and R

$
0
0

The quick version of this post goes like this:
-- # in Stata is : in R
-- ## in Stata is * in R.

The long version is that both Stata and R handle very nicely factor variables in regression models. If you want a full-factorial interaction between a factor variable x1 and a continuous variable x2, the Stata way is to say


regress y i.x1##c.x2

whereas the R way is to say


lm(y~factor(x1)*x2)

Now, if you just want to interact x1 with the slope of x2, the Stata way becomes


regress y i.x1#c.x2

whereas the R way becomes


lm(y~factor(x1):x2)

That's all.


Viewing all articles
Browse latest Browse all 48

Trending Articles