Hello everyone,
I have an unbalanced daily panel data which looks like below. "Pastdefault" and "No_pastdefault" are the 2 variables that I want to create.
a. If a seller defaults at time t, "pastdefault" will equal 1 for all subsequent observations. I have tried the codes below, but it just sets 1 for the t+1 observations.
forvalues i = 1/`=_n' {
2. by sellerid: gen pastdefault=1 if default[_n-`i']==1
3. }
b. I also need to count the number of times a seller has defaulted and create "No_pastdefault" as in the table.
Please could anyone help me with these two questions? Thank you very much.
I have an unbalanced daily panel data which looks like below. "Pastdefault" and "No_pastdefault" are the 2 variables that I want to create.
a. If a seller defaults at time t, "pastdefault" will equal 1 for all subsequent observations. I have tried the codes below, but it just sets 1 for the t+1 observations.
forvalues i = 1/`=_n' {
2. by sellerid: gen pastdefault=1 if default[_n-`i']==1
3. }
b. I also need to count the number of times a seller has defaulted and create "No_pastdefault" as in the table.
Please could anyone help me with these two questions? Thank you very much.
TradeID | SellerID | time | Default | Pastdefault | No_pastdefault |
11 | 1 | 12/01/2015 | 0 | 0 | 0 |
12 | 1 | 15/01/2015 | 1 | 0 | 0 |
13 | 1 | 20/06/2016 | 0 | 1 | 1 |
14 | 1 | 30/09/2016 | 1 | 1 | 1 |
15 | 1 | 14/01/2017 | 0 | 1 | 2 |
21 | 2 | 10/02/2014 | 1 | 0 | 0 |
22 | 2 | 15/02/2014 | 0 | 1 | 1 |
Comment