Regression on a subset in R
问题 I want to run the same regression for different countries (i.e. subsets of my data). I did figure out how to do in R, but after doing the same thing with much more ease in Stata, I wonder if there's a better way in R. In Stata you would do something like this: foreach country in USA UK France { reg y x1 x2 if country == "`country'" } Simple and human-readable, right? In R, I come up with split and ddply methods, both are more complicated. To use split data.subset <- split(data, data$country)