Announcement

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

  • Convert quarterly data to monthly (quarterly value in second month of quarter, else null)

    How do I convert quarterly series into monthly series?
    I would like the quarterly value in the second month of the quarter, else null.
    THANKS!

    QDate P12 P13
    2000Q1 72.5 75.9
    2000Q2 73.1 76.4
    2000Q3 75.8 77.5
    2000Q4 76.1 78.4
    2001Q1 76.9 78.2
    2001Q2 77.5 78.9
    2001Q3 77.8 79.4
    2001Q4 78.4 79.8
    2002Q1 79.1 80.3
    2002Q2 79.7 81.1
    2002Q3 80.2 81.4
    2002Q4 80.8 81.9
    2003Q1 81.9 82.2
    2003Q2 81.9 82.2
    2003Q3 82.3 82.6
    2003Q4 82.7 83.2
    2004Q1 83.5 83.5
    2004Q2 83.9 84.2
    2004Q3 84.2 84.7
    2004Q4 84.9 85.4

    MDate P12M P13M
    2000m1 - -
    2000m2 72.5 75.9
    2000m3 - -
    2000m4 - -
    2000m5 73.1 76.4
    2000m6 - -
    2000m7 - -
    2000m8 75.8 77.5
    2000m9 - -
    etc

  • #2
    This will do what you want:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float qdate double(p12 p13)
    160 72.5 75.9
    161 73.1 76.4
    162 75.8 77.5
    163 76.1 78.4
    164 76.9 78.2
    165 77.5 78.9
    166 77.8 79.4
    167 78.4 79.8
    168 79.1 80.3
    169 79.7 81.1
    170 80.2 81.4
    171 80.8 81.9
    172 81.9 82.2
    173 81.9 82.2
    174 82.3 82.6
    175 82.7 83.2
    176 83.5 83.5
    177 83.9 84.2
    178 84.2 84.7
    179 84.9 85.4
    end
    format %tq qdate
    
    
    //    GET MONTH AT BEGINNING OF QUARTER
    gen mdate = mofd(dofq(qdate))
    
    //    NOW EXPAND EACH OBSERVATION TO 3
    //    (ONE FOR EACH MONTH OF THE QUARTER)
    format mdate %tm
    expand 3
    by qdate, sort: replace mdate = mdate + _n - 1
    
    //    REPLACE P12 P23 BY MISSING VALUE FOR
    //    FIRST AND THIRD MONTH OF EACH QUARTER
    by qdate: replace p12 = . if inlist(_n, 1, 3)
    In the future, please post example data by using the -dataex- command. The kind of listing shown in your post is awkward to import into Stata and work with. By using -dataex- you make it possible for those who want to help you to make a completely faithful replica of your Stata example with a simple copy/paste operation. You can get the -dataex- command by running -ssc install dataex-. Then run -help dataex- to read the simple instructions for using it. Please use -dataex- whenever you post example data in the future.

    Comment

    Working...
    X