I am new to R and working on a project, and I was asked to do something more complex than what I can do now.
So, I have a dataset that looks like this:
Obs. Democracy
1 1
2 0
3 1
4 0
5 1
6 1
7 1
8 0
9 0
10 1
The dataset has other control variables, but an important variable is binary for democracy. We performed OLS regression of the current data, and now we collect a list of regressions - where the independent variable changes.
I am trying to create a function in which it changes the democracy variable from 0 to 1 line by line and starts and saves the OLS regression between each change.
I read a little about loops, bundles, and functions, but couldn't write anything close to what we are looking for.
The best I managed to create is not close:
my.function <- function (data$democracy){
GB1 <- ifelse(data$democracy[x,]==1, 1, 1)
return(regression[x] <- glm(leader ~ democracy))
}
, , , .
!