Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a huge database and I need to run different regressions with conditional statements. So I see to options to do it: 1) in the regression include the command data subset (industrycodes==12) and 2) I don't obtain the same results as if cut the data to the values when furniture==12. And they should be the same. Could somebody help me with the codes, I think I have a problem with this. I put an example very basic to explain it.

ID  roa   employees    industrycodes
1   0,5      10              12
2   0,3      20              11
3   0,8      15              12
4   0,2      12              12
5   0,7      13              11
6   0,4       8              12

so first I create the subdatabase to compare (when the industry code is 12)

data2<-data1[data1$industrycodes==12,]

and here I run the regressions:

1) for the whole data taking only industrycodes==12 --> here I have the 6 observations

summary(lm(data1$roa~data1$employees, data=subset(data1,industrycodes==12)))  

2) cutting the sample when the industrycode==12 --> here of course I have 4 observations

summary(lm(data2$roa~data2$employees),data=data2)

Any ideas of what can be wrong?? Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
270 views
Welcome To Ask or Share your Answers For Others

1 Answer

The problem is that in the first you specify a dataset ( the one called subset(data1,industrycodes==12)) but then run the lm in another datset (data1 - the original one).

An extra comment is that since you use the command data=... in the lm you do not have to specify the variables with the $ , it works as an in the function lm attach command.

try this:

data3<- subset(data1,industrycodes==12)

summary(lm(roa~employees, data=data3) )

Hope it works


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...