Hi!
I have an issue trying to create a new variable using the if command.
My data looks like this (but contains >5000 rows):
date_1 has the format %d and type float, date_2 has the format %tcDD-Mon-CCYY and type double.
I want to create a new variable that put 1 if (date_1 is <= date_2 - 10 days) AND (date_1 is >=date_2 - 100 days) and 0 if these conditions are not fulfilled.
The code I have tried look like this:
generate newvar =.
replace newvar = 1 if date_1 <= date_2 - 10 & date_1 >=date_2 - 100
replace newvar = 0 if date_1 > date_2 - 10 & date_1 <date_2 - 100
The result should be
But instead it goes like this for all 5000+ rows
What am I doing wrong?
Thank you so much for helping me
I have an issue trying to create a new variable using the if command.
My data looks like this (but contains >5000 rows):
id | date_1 | date_2 |
01 | 20dec2005 | 9-Dec-2005 |
02 | 30dec2010 | 5-Jan-2010 |
03 | 01jan2010 | 25-Nov-2009 |
I want to create a new variable that put 1 if (date_1 is <= date_2 - 10 days) AND (date_1 is >=date_2 - 100 days) and 0 if these conditions are not fulfilled.
The code I have tried look like this:
generate newvar =.
replace newvar = 1 if date_1 <= date_2 - 10 & date_1 >=date_2 - 100
replace newvar = 0 if date_1 > date_2 - 10 & date_1 <date_2 - 100
The result should be
id | date_1 | date_2 | newvar |
01 | 20dec2005 | 9-Dec-2005 | 1 |
02 | 30dec2010 | 5-Jan-2010 | 0 |
But instead it goes like this for all 5000+ rows
id | date_1 | date_2 | newvar |
01 | 20dec2005 | 9-Dec-2005 | . |
02 | 30dec2010 | 5-Jan-2010 | . |
Thank you so much for helping me
Comment