Hello everyone!
I am relatively new to Stata but have some previous experience with R.
I am stuck with a relatively simple problem: my data is sorted by date value, and each date value occurs two times in the data set.
Besides date value, the data contains two variables, let's call them 'minimum' and 'maximum'.
Every other row has the value for minimum while maximum being missing, and every other row has the value for maximum while minimum being missing.
How can I combine these two rows with same date value to one row containing values for date, minimum and maximum?
The data looks like this:
date - - - - - - - - - minimum - - - - - - - - - maximum
19980101 - - - - - -5 - - - - -- - - - - - - - - - - - - .
19980101 - - - - - - . - - - - - - - - - - - - - - - - - 17
19980102 - - - - - -8 - - - - - - - - - - - - - - - - - - .
19980102 - - - - - - . - - - - - - - - - - - - - - - - - 14
19980103 - - - - - -3 - - - - - - - - - - - - - - - - - .
19980103 - - - - - - . - - - - - - - - - - - - - - - - - 15
...
...
...
If I were to do this with R I would simply sort by date and then loop over all rows and append every odd index value from column1 and column2 to their own lists, and every even indexed value from column3 to another list, then combine the lists according to index value.
Am I missing something simple here, or am I perhaps not knowing how to look at this problem through the-Stata-way-of-doing-things glasses?
Thank you already in advance!
I am relatively new to Stata but have some previous experience with R.
I am stuck with a relatively simple problem: my data is sorted by date value, and each date value occurs two times in the data set.
Besides date value, the data contains two variables, let's call them 'minimum' and 'maximum'.
Every other row has the value for minimum while maximum being missing, and every other row has the value for maximum while minimum being missing.
How can I combine these two rows with same date value to one row containing values for date, minimum and maximum?
The data looks like this:
date - - - - - - - - - minimum - - - - - - - - - maximum
19980101 - - - - - -5 - - - - -- - - - - - - - - - - - - .
19980101 - - - - - - . - - - - - - - - - - - - - - - - - 17
19980102 - - - - - -8 - - - - - - - - - - - - - - - - - - .
19980102 - - - - - - . - - - - - - - - - - - - - - - - - 14
19980103 - - - - - -3 - - - - - - - - - - - - - - - - - .
19980103 - - - - - - . - - - - - - - - - - - - - - - - - 15
...
...
...
If I were to do this with R I would simply sort by date and then loop over all rows and append every odd index value from column1 and column2 to their own lists, and every even indexed value from column3 to another list, then combine the lists according to index value.
Am I missing something simple here, or am I perhaps not knowing how to look at this problem through the-Stata-way-of-doing-things glasses?
Thank you already in advance!

Comment