Displaying 3 results from an estimated 3 matches for "fkdf".
Did you mean:
ffdf
2018 May 29
0
How to generate a conditional dummy in R?
Hi Faradj,
What a problem! I think I have worked it out, but only because the
result is the one you said you wanted.
# the sample data frame is named fkdf
Y2Xby3<-function(x) {
nrows<-dim(x)[1]
X<-rep(0,nrows)
for(i in 1:(nrows-2)) {
if(!is.na(x$Y[i])) {
if(x$Y[i] == 1 && any(is.na(x$Y[(i+1):(i+2)]))) X[i]<-1
if(i > 1) {
if(X[i-1] == 1) X[i]<-0
}
}
else {
if(!is.na(x$Y[i+1])) {
if(x$Y[i+1] == 1 &...
2018 May 29
1
How to generate a conditional dummy in R?
...USSR Yugoslavia etc).
Best,
Faradj
> 29 maj 2018 kl. 02:15 skrev Jim Lemon <drjimlemon at gmail.com>:
>
> Hi Faradj,
> What a problem! I think I have worked it out, but only because the
> result is the one you said you wanted.
>
> # the sample data frame is named fkdf
> Y2Xby3<-function(x) {
> nrows<-dim(x)[1]
> X<-rep(0,nrows)
> for(i in 1:(nrows-2)) {
> if(!is.na(x$Y[i])) {
> if(x$Y[i] == 1 && any(is.na(x$Y[(i+1):(i+2)]))) X[i]<-1
> if(i > 1) {
> if(X[i-1] == 1) X[i]<-0
> }
> }
> else {
>...
2018 May 28
3
How to generate a conditional dummy in R?
Hi everyone,
I am trying to generate a conditional dummy variable ?X" with the following rules
set X=1 if Y is =1, two years prior to the NA. [0,0,NA].
For example, if the pattern for Y is 0,0,NA then the X variable is =0 for all the two years prior to the NA. If the pattern for Y is 0,1,NA or 1,0,NA then the X =1 . To be clear, if 1,1,NA then the X=1 that first specific year, it