Hi,
I'm currently working with an id variable, which identifies my observation units. I have a numeric variable (kilos) for certain days per id. I also have a date (date_app) indicating when each observation unit (id) first used a mobile application. This starting date is different for each observation unit. I'd like to know how to create a new date variable, which takes the value of 0 if the date is equal to date_app (I've already done this part), negative values for each day before this date, and positive values for each day after this date.
Here is an extract from my data using the dataex command:
For example, taking the first line of obs., I want the variable new_date = 0 when id=1 and date_trans=22945, and new_date =-754 when id=1 and date_trans=22191, and so on...
My aim is to plot the kilos variable over days for each id, putting the date on which the mobile application was first used at the center of the graph.
I'm currently working with an id variable, which identifies my observation units. I have a numeric variable (kilos) for certain days per id. I also have a date (date_app) indicating when each observation unit (id) first used a mobile application. This starting date is different for each observation unit. I'd like to know how to create a new date variable, which takes the value of 0 if the date is equal to date_app (I've already done this part), negative values for each day before this date, and positive values for each day after this date.
Here is an extract from my data using the dataex command:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(date_trans id) double kilos float(date_app new_date) 22191 1 8668 22945 . 22192 1 7434 22945 . 22197 1 820 22945 . 22200 1 3235 22945 . 22203 1 2400 22945 . 22205 1 11824 22945 . 22206 1 3298 22945 . 22213 1 3199 22945 . 22215 1 3400 22945 . 22219 1 1019 22945 . 22224 1 100 22945 . 22228 1 13951 22945 . 22234 1 4801 22945 . 22241 1 12529 22945 . 22243 1 10035 22945 . 22248 1 3957 22945 . 22255 1 2411 22945 . 22267 1 2478 22945 . 22275 1 1920 22945 . 22279 1 3840 22945 . 22284 1 984 22945 . 22286 1 2862 22945 . 22287 1 4001 22945 . 22291 1 4249 22945 . 22294 1 10856 22945 . 22374 1 11576 22945 . 22393 1 5857 22945 . 22554 1 2514 22945 . 22555 1 13616 22945 . 22556 1 4435 22945 . 22557 1 5610 22945 . 22558 1 1803 22945 . 22559 1 1100 22945 . 22560 1 329 22945 . 22561 1 3028 22945 . 22562 1 558 22945 . 22563 1 5312 22945 . 22564 1 4335 22945 . 22568 1 317 22945 . 22570 1 372 22945 . 22571 1 331 22945 . 22573 1 2269 22945 . 22574 1 1104 22945 . 22575 1 405 22945 . 22576 1 626 22945 . 22577 1 2037 22945 . 22578 1 815 22945 . 22580 1 627 22945 . 22581 1 2236 22945 . 22582 1 245 22945 . 22583 1 1469 22945 . 22584 1 657 22945 . 22586 1 1292 22945 . 22587 1 1791 22945 . 22591 1 2568 22945 . 22629 1 1030 22945 . 22630 1 2051 22945 . 22631 1 3723 22945 . 22632 1 2815 22945 . 22633 1 1508 22945 . 22635 1 572 22945 . 22644 1 339 22945 . 22646 1 1745 22945 . 22647 1 1589 22945 . 22648 1 1991 22945 . 22649 1 254 22945 . 22650 1 486 22945 . 22651 1 4123 22945 . 22652 1 1849 22945 . 22653 1 762 22945 . 22654 1 430 22945 . 22655 1 439 22945 . 22656 1 1054 22945 . 22657 1 2000 22945 . 22658 1 3528 22945 . 22659 1 2269 22945 . 22660 1 3178 22945 . 22661 1 2804 22945 . 22662 1 1407 22945 . 22663 1 234 22945 . 22664 1 1889 22945 . 22669 1 1261 22945 . 22670 1 2009 22945 . 22671 1 156 22945 . 22672 1 1654 22945 . 22673 1 2032 22945 . 22674 1 2263 22945 . 22675 1 1506 22945 . 22676 1 739 22945 . 22684 1 156 22945 . 22686 1 780 22945 . 22687 1 3112 22945 . 22688 1 832 22945 . 22689 1 1093 22945 . 22690 1 542 22945 . 22740 1 463 22945 . 22741 1 647 22945 . 22742 1 229 22945 . 22743 1 112 22945 . 22746 1 1207 22945 . end format %td date_trans
For example, taking the first line of obs., I want the variable new_date = 0 when id=1 and date_trans=22945, and new_date =-754 when id=1 and date_trans=22191, and so on...
My aim is to plot the kilos variable over days for each id, putting the date on which the mobile application was first used at the center of the graph.
Comment