Konstantinos Gk - 7 months ago 52

R Question

I want to run the following regressions, the variable which has the problem is EP, is a dummy variable and I must to check different cases, z (lenght=1000) is the threshold variable. Ι want to crate 1000 different variables of EP from z variable and save the coefficients. I use a loop in loop but the results are completely wrong.Any idea?

`for (k in 1:1000){`

z<-u[k]

for (i in 1:length(dS)){

if (dS[i]>=z) {

EP[i]=1

} else {

EP[i]=0

}

fitT <- dynlm(dR ~ L(dR,1)+L(EN)+L(EP)+L(ΚΜ,1)

prob[[k]] <- summary(fitT)$coefficients[1, 2]

}

Answer

You don't have a closing `}`

for the `i`

-loop; you also don't have a closing `)`

for `dynlm`

.

Note, you can really replace your i-loop by

```
EP <- as.integer(dS >= z)
```

Next time when asking question, be clear and specific. What do you mean by "I use a loop in loop but the results are completely wrong"? Error message, etc?