Hi Clyde and Nick,
I want to generate a new variable "wanted" from the following database:
I have generated post_dmg using this code:
Please help me to write a code for "wanted". Suppose a disaster happens at period t in county i. The cost of damage is x, and the duration of the disaster is n. Then, I want to place x in the following n period until the effect of the disaster disappears. In the meantime, I will add x1 and x2 in the common period if another disaster happens (please see 2022m11).
Thanks in advance.
Kind Regards,
Woahid
I want to generate a new variable "wanted" from the following database:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float t byte(county duration) int damage byte post_dmg int wanted 744 1 0 0 0 0 745 1 0 0 0 0 746 1 2 223 1 223 747 1 0 0 1 223 752 1 0 0 0 0 753 1 6 1456 1 1456 754 1 0 0 1 1456 760 1 0 0 0 0 765 1 0 0 0 0 766 1 0 0 0 0 767 1 0 0 0 0 768 1 2 159 1 159 769 1 0 0 1 159 773 1 0 0 0 0 744 2 4 657 1 657 745 2 0 0 1 657 746 2 0 0 1 657 747 2 0 0 1 657 748 2 0 0 0 0 753 2 2 146 1 146 754 2 2 342 1 488 755 2 0 0 1 342 765 2 0 0 0 0 766 2 0 0 0 0 767 2 0 0 0 0 768 2 0 0 0 0 769 2 0 0 0 0 770 2 0 0 0 0 end format %tm t
Code:
xtset county t, monthly gen byte original = 1 tsfill clonevar countdown = duration by county : replace countdown = max(countdown, L.countdown - 1, 0) by county : gen post_dmg = countdown>0 keep if original == 1 drop countdown original
Thanks in advance.
Kind Regards,
Woahid
Comment