Hi Nick Cox and Clyde Schechter,
I have a very simple question, but I do not how to solve it. My problem is as follows: I have near to 600 variables which are from _02Jan2020 to _31Jan2020 (all of them are integers). They are ordered, so I want to obtain multiple outcome variables that are defined as the difference between a column and the previous one. For instance, _03Jan2020_new must be (_03Jan2020 - _02Jan2020), _04Jan2020_new must be (_04Jan2020 - _03Jan2020), and so on. I tried to do this task with the following code, but it did not work. Do you have any thought about how to solve it?
Thanks in advance!
I have a very simple question, but I do not how to solve it. My problem is as follows: I have near to 600 variables which are from _02Jan2020 to _31Jan2020 (all of them are integers). They are ordered, so I want to obtain multiple outcome variables that are defined as the difference between a column and the previous one. For instance, _03Jan2020_new must be (_03Jan2020 - _02Jan2020), _04Jan2020_new must be (_04Jan2020 - _03Jan2020), and so on. I tried to do this task with the following code, but it did not work. Do you have any thought about how to solve it?
Thanks in advance!
Code:
foreach x of varlist _02Jan2020-_31Dec2021 { local prev = `x'-1 gen `x'_new = `x' - `prev' }
Comment