Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating time series of (quarter) date variables for the period between two date variables: beginning and end of ownership

    Hi,

    I would much appreciate your assistance with the below question.

    Please, I have data set that contains information on assets and their holding periods. The data contains 4 variables: 1- Asset number (asset_no), 2- starting period of ownership (acquisition_quarter) in format year quarter; ex. 2006q1), 3- Ending period of ownership (sold_quarter) in format year quarter; ex. 2006q4, and 4- the number of quarters between start and end of ownership (ownership_quarter) in numbers ex. 3 means three-quarters of ownership.

    Note that the asset_no uniquely identify each observation

    here is an example of the data


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long asset_no float(acquisition_quarter sold_quarter ownership_quarter)
    242764 215 216   1
     39555 155 167  12
     90357 185 199  14
    273042 219 233  14
    200185 209 223  14
    122935 183 199  16
    291848 223 240  17
     11072 134 165  31
     75284 177 208  31
     13124 135 167  32
    211298 211 243  32
     52943 159 195  36
     27595 149 186  37
     66343 151 191  40
     22736 147 189  42
    213965 182 233  51
     27479 135 188  53
      5713 137 202  65
     15682  79 188 109
    343082  91 233 142
    end
    format %tq acquisition_quarter
    format %tq sold_quarter
    what I need is to create a time series of ownership periods, in other words converting the number of ownership quarters into quarter dates starting with the acquisition quarters then adding 1 (quarter) up till the number of quarters in the ownership_quarter variable. for example. if asset no. 1 has acquisition_quarter = 2006q1 and sold_quarter 2006q4 hence it has been owned for 4 quarters. then this observation would have ownership_1 = 2006q1 ownership_2 2006q2 ownership_3 2006q3 ownership_4 2006q4.

    I hope my question is clear and Thank you a lot in advance.

    Regards,
    Islam Ibrahim

  • #2
    Thanks for data example and clear question

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long asset_no float(acquisition_quarter sold_quarter ownership_quarter)
    242764 215 216   1
     39555 155 167  12
     90357 185 199  14
    273042 219 233  14
    200185 209 223  14
    122935 183 199  16
    291848 223 240  17
     11072 134 165  31
     75284 177 208  31
     13124 135 167  32
    211298 211 243  32
     52943 159 195  36
     27595 149 186  37
     66343 151 191  40
     22736 147 189  42
    213965 182 233  51
     27479 135 188  53
      5713 137 202  65
     15682  79 188 109
    343082  91 233 142
    end
    format %tq acquisition_quarter
    format %tq sold_quarter
    
    gen toexpand = own + 1 
    expand toexpand 
    bysort asset_no: gen qtime = acq + _n - 1 
    format qtime %tq 
    list if own <= 14, sepby(asset_no) 
    
         +---------------------------------------------------------------+
         | asset_no   acquis~r   sold_q~r   owners~r   toexpand    qtime |
         |---------------------------------------------------------------|
    377. |    39555     1998q4     2001q4         12         13   1998q4 |
    378. |    39555     1998q4     2001q4         12         13   1999q1 |
    379. |    39555     1998q4     2001q4         12         13   1999q2 |
    380. |    39555     1998q4     2001q4         12         13   1999q3 |
    381. |    39555     1998q4     2001q4         12         13   1999q4 |
    382. |    39555     1998q4     2001q4         12         13   2000q1 |
    383. |    39555     1998q4     2001q4         12         13   2000q2 |
    384. |    39555     1998q4     2001q4         12         13   2000q3 |
    385. |    39555     1998q4     2001q4         12         13   2000q4 |
    386. |    39555     1998q4     2001q4         12         13   2001q1 |
    387. |    39555     1998q4     2001q4         12         13   2001q2 |
    388. |    39555     1998q4     2001q4         12         13   2001q3 |
    389. |    39555     1998q4     2001q4         12         13   2001q4 |
         |---------------------------------------------------------------|
    500. |    90357     2006q2     2009q4         14         15   2006q2 |
    501. |    90357     2006q2     2009q4         14         15   2006q3 |
    502. |    90357     2006q2     2009q4         14         15   2006q4 |
    503. |    90357     2006q2     2009q4         14         15   2007q1 |
    504. |    90357     2006q2     2009q4         14         15   2007q2 |
    505. |    90357     2006q2     2009q4         14         15   2007q3 |
    506. |    90357     2006q2     2009q4         14         15   2007q4 |
    507. |    90357     2006q2     2009q4         14         15   2008q1 |
    508. |    90357     2006q2     2009q4         14         15   2008q2 |
    509. |    90357     2006q2     2009q4         14         15   2008q3 |
    510. |    90357     2006q2     2009q4         14         15   2008q4 |
    511. |    90357     2006q2     2009q4         14         15   2009q1 |
    512. |    90357     2006q2     2009q4         14         15   2009q2 |
    513. |    90357     2006q2     2009q4         14         15   2009q3 |
    514. |    90357     2006q2     2009q4         14         15   2009q4 |
         |---------------------------------------------------------------|
    532. |   200185     2012q2     2015q4         14         15   2012q2 |
    533. |   200185     2012q2     2015q4         14         15   2012q3 |
    534. |   200185     2012q2     2015q4         14         15   2012q4 |
    535. |   200185     2012q2     2015q4         14         15   2013q1 |
    536. |   200185     2012q2     2015q4         14         15   2013q2 |
    537. |   200185     2012q2     2015q4         14         15   2013q3 |
    538. |   200185     2012q2     2015q4         14         15   2013q4 |
    539. |   200185     2012q2     2015q4         14         15   2014q1 |
    540. |   200185     2012q2     2015q4         14         15   2014q2 |
    541. |   200185     2012q2     2015q4         14         15   2014q3 |
    542. |   200185     2012q2     2015q4         14         15   2014q4 |
    543. |   200185     2012q2     2015q4         14         15   2015q1 |
    544. |   200185     2012q2     2015q4         14         15   2015q2 |
    545. |   200185     2012q2     2015q4         14         15   2015q3 |
    546. |   200185     2012q2     2015q4         14         15   2015q4 |
         |---------------------------------------------------------------|
    632. |   242764     2013q4     2014q1          1          2   2013q4 |
    633. |   242764     2013q4     2014q1          1          2   2014q1 |
         |---------------------------------------------------------------|
    634. |   273042     2014q4     2018q2         14         15   2014q4 |
    635. |   273042     2014q4     2018q2         14         15   2015q1 |
    636. |   273042     2014q4     2018q2         14         15   2015q2 |
    637. |   273042     2014q4     2018q2         14         15   2015q3 |
    638. |   273042     2014q4     2018q2         14         15   2015q4 |
    639. |   273042     2014q4     2018q2         14         15   2016q1 |
    640. |   273042     2014q4     2018q2         14         15   2016q2 |
    641. |   273042     2014q4     2018q2         14         15   2016q3 |
    642. |   273042     2014q4     2018q2         14         15   2016q4 |
    643. |   273042     2014q4     2018q2         14         15   2017q1 |
    644. |   273042     2014q4     2018q2         14         15   2017q2 |
    645. |   273042     2014q4     2018q2         14         15   2017q3 |
    646. |   273042     2014q4     2018q2         14         15   2017q4 |
    647. |   273042     2014q4     2018q2         14         15   2018q1 |
    648. |   273042     2014q4     2018q2         14         15   2018q2 |
         +---------------------------------------------------------------+
         
    * ???  drop *quarter

    Comment


    • #3
      Thank you Nick for your prompt reply and your always valuable support. That was very helpful.

      Comment

      Working...
      X