Announcement

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

  • Looping over the same GDP variable over vintages of time

    Hi all
    I have Gross Domestic Product, gdp, data that are in vintages (i.e. the gdp variable is revised over time, so gdp65Q4 below is the gdp data revised at a vintage date of year 1965 quarter 4. Therefore for each column below we have gdp data for each quarter measured on a specific vintage date. The next column will show how the gdp for the same quarters have been revised in a subsequent vintage date and so on. To clarify more, the first cell 306.4 on the north west corner represents gdp in quarter 1 year 1947 but as revised in quarter 4 of year 1965, the next cell to the right 307.4 represents gdp in quarter 1 year 1947 again but as revised in quarter 1 year 1966....and so on)

    date gdp65Q4 gdp66Q1 gdp66Q2 gdp66Q3
    1947:Q1 306.4 307.4 309.4 302.4
    1947:Q2 309 301 302 309
    1947:Q3 309.6 304.6 308.6 302.6
    1947:Q4 314.5 315.5 314.5 310.5
    1948:Q1 317.1 311.2 314.3 319.1
    1948:Q2 322.9 325.7 333.9 322.9
    What I want to do is to generate a variable that represents gdp vintage shock and measured as residual of a regression of gdp at a given vintage date on the same gdp at a previous vintage date.
    I do not know how a loop can estimate that ?

    Thank you
    Last edited by Lisa Wilson; 18 Oct 2016, 14:18.

  • #2
    If I understand correctly, you'd want one residual value per date (e.g. 1947Q2) per vintage(e.g. gp65Q4)? So for the table show, you'd get 6x4 residuals? (Or more precisely, 6x3 as you don't have gdp65Q3)

    Comment


    • #3
      Jesse: thanks a lot for your reply.
      Well, the data extends vertically from 1947 Q1 to 2015:Q1 (time) . The revised GDP variable extends horizontally from gdp65Q4(revised gdp data in year 1965 Q4) to gdp16Q1 (revised gdp data in year 2016 Q1)


      I think of converting the table here to shocks (residuals) measured from a regression of vintage gdp variable on a previous vintage gdp variable. For example, I want to regress gdp (of vintage year 2015 Q4) on gdp (of vintage year 2015 Q4) for each given time period, for exampleyear 1990 Q1, 1990 Q2, 1990 Q3, ....and so on.

      Comment


      • #4
        Can you add a data example using -dataex- (see the FAQ of this forum)? That would make it easier to try to come up with code examples. Either way you'll have to reshape your data to long first I think.

        Comment


        • #5
          Thanks. Here you go
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str7 date str5(routput65q4 routput66q1 routput66q2 routput66q3 routput66q4 routput67q1 routput67q2 routput67q3 routput67q4 routput68q1 routput68q2 routput68q3 routput68q4 routput69q1 routput69q2)
          "1947:Q1" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4" "306.4"
          "1947:Q2" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0" "309.0"
          "1947:Q3" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6" "309.6"
          "1947:Q4" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5" "314.5"
          "1948:Q1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1" "317.1"
          "1948:Q2" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9" "322.9"
          "1948:Q3" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8" "325.8"
          "1948:Q4" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7" "328.7"
          "1949:Q1" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5" "324.5"
          "1949:Q2" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5" "322.5"
          "1949:Q3" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1" "326.1"
          "1949:Q4" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3" "323.3"
          "1950:Q1" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6" "339.6"
          "1950:Q2" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5" "348.5"
          "1950:Q3" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8" "362.8"
          "1950:Q4" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1" "370.1"
          "1951:Q1" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8" "374.8"
          "1951:Q2" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5" "381.5"
          "1951:Q3" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7"
          "1951:Q4" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7" "388.7"
          "1952:Q1" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4" "391.4"
          "1952:Q2" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6" "389.6"
          "1952:Q3" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9" "393.9"
          "1952:Q4" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3" "405.3"
          "1953:Q1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1" "412.1"
          "1953:Q2" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4" "416.4"
          "1953:Q3" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7" "413.7"
          "1953:Q4" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8" "408.8"
          "1954:Q1" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9" "402.9"
          "1954:Q2" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1" "402.1"
          "1954:Q3" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2" "407.2"
          "1954:Q4" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7" "415.7"
          "1955:Q1" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0" "428.0"
          "1955:Q2" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4" "435.4"
          "1955:Q3" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1" "442.1"
          "1955:Q4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4" "446.4"
          "1956:Q1" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6" "443.6"
          "1956:Q2" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6" "445.6"
          "1956:Q3" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5" "444.5"
          "1956:Q4" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3" "450.3"
          "1957:Q1" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4" "453.4"
          "1957:Q2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2" "453.2"
          "1957:Q3" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2" "455.2"
          "1957:Q4" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2" "448.2"
          "1958:Q1" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5" "437.5"
          "1958:Q2" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5" "439.5"
          "1958:Q3" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7" "450.7"
          "1958:Q4" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6" "461.6"
          "1959:Q1" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6" "468.6"
          "1959:Q2" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9" "479.9"
          "1959:Q3" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0" "475.0"
          "1959:Q4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4" "480.4"
          "1960:Q1" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2" "490.2"
          "1960:Q2" "489.8" "489.8" "489.8" "489.7" "489.7" "489.7" "489.7" "489.7" "489.7" "489.7" "489.7" "489.7" "489.7" "489.7" "489.7"
          "1960:Q3" "487.4" "487.4" "487.4" "487.3" "487.3" "487.3" "487.3" "487.3" "487.3" "487.3" "487.3" "487.3" "487.3" "487.3" "487.3"
          "1960:Q4" "483.8" "483.8" "483.8" "483.7" "483.7" "483.7" "483.7" "483.7" "483.7" "483.7" "483.7" "483.7" "483.7" "483.7" "483.7"
          "1961:Q1" "482.7" "482.7" "482.7" "482.6" "482.6" "482.6" "482.6" "482.6" "482.6" "482.6" "482.6" "482.6" "482.6" "482.6" "482.6"
          "1961:Q2" "492.9" "492.9" "492.9" "492.8" "492.8" "492.8" "492.8" "492.8" "492.8" "492.8" "492.8" "492.8" "492.8" "492.8" "492.8"
          "1961:Q3" "501.6" "501.6" "501.6" "501.5" "501.5" "501.5" "501.5" "501.5" "501.5" "501.5" "501.5" "501.5" "501.5" "501.5" "501.5"
          "1961:Q4" "511.9" "511.9" "511.9" "511.7" "511.7" "511.7" "511.7" "511.7" "511.7" "511.7" "511.7" "511.7" "511.7" "511.7" "511.7"
          "1962:Q1" "519.7" "519.7" "519.7" "519.5" "519.5" "519.5" "519.5" "519.5" "519.5" "519.5" "519.5" "519.5" "519.5" "519.5" "519.5"
          "1962:Q2" "527.9" "527.9" "527.9" "527.7" "527.7" "527.7" "527.7" "527.7" "527.7" "527.7" "527.7" "527.7" "527.7" "527.7" "527.7"
          "1962:Q3" "533.6" "533.6" "533.6" "533.4" "533.4" "533.4" "533.4" "533.4" "533.4" "533.4" "533.4" "533.4" "533.4" "533.4" "533.4"
          "1962:Q4" "538.5" "538.5" "538.5" "538.3" "538.3" "538.3" "538.3" "538.3" "538.3" "538.3" "538.3" "538.3" "538.3" "538.3" "538.3"
          "1963:Q1" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2" "541.2"
          "1963:Q2" "544.9" "544.9" "544.9" "546.0" "546.0" "546.0" "546.0" "546.0" "546.0" "546.0" "546.0" "546.0" "546.0" "546.0" "546.0"
          "1963:Q3" "553.7" "553.7" "553.7" "554.7" "554.7" "554.7" "554.7" "554.7" "554.7" "554.7" "554.7" "554.7" "554.7" "554.7" "554.7"
          "1963:Q4" "560.0" "560.0" "560.0" "562.1" "562.1" "562.1" "562.1" "562.1" "562.1" "562.1" "562.1" "562.1" "562.1" "562.1" "562.1"
          "1964:Q1" "567.1" "567.1" "567.1" "569.7" "569.7" "569.7" "569.7" "571.1" "571.1" "571.1" "571.1" "571.1" "571.1" "571.1" "571.1"
          "1964:Q2" "575.9" "575.9" "575.9" "578.1" "578.1" "578.1" "578.1" "578.6" "578.6" "578.6" "578.6" "578.6" "578.6" "578.6" "578.6"
          "1964:Q3" "582.6" "582.6" "582.6" "585.0" "585.0" "585.0" "585.0" "585.8" "585.8" "585.8" "585.8" "585.8" "585.8" "585.8" "585.8"
          "1964:Q4" "584.7" "584.7" "584.7" "587.2" "587.2" "587.2" "587.2" "588.5" "588.5" "588.5" "588.5" "588.5" "588.5" "588.5" "588.5"
          "1965:Q1" "597.5" "597.7" "597.7" "600.3" "600.3" "600.3" "600.3" "601.5" "601.5" "601.5" "601.5" "601.6" "601.6" "601.6" "601.6"
          "1965:Q2" "601.4" "603.5" "603.5" "607.8" "607.8" "607.8" "607.8" "609.7" "609.7" "609.7" "609.7" "610.4" "610.4" "610.4" "610.4"
          "1965:Q3" "609.1" "613.0" "613.0" "618.2" "618.2" "618.2" "618.2" "620.7" "620.7" "620.7" "620.7" "622.5" "622.5" "622.5" "622.5"
          "1965:Q4" "#N/A"  "621.7" "624.4" "631.2" "631.2" "631.2" "631.2" "634.4" "634.4" "634.4" "634.4" "636.6" "636.6" "636.6" "636.6"
          "1966:Q1" "#N/A"  "#N/A"  "633.8" "640.5" "640.5" "640.5" "640.5" "645.4" "645.4" "645.4" "645.4" "648.6" "648.6" "648.6" "648.6"
          "1966:Q2" "#N/A"  "#N/A"  "#N/A"  "644.2" "643.5" "643.5" "643.5" "649.3" "649.3" "649.3" "649.3" "653.3" "653.3" "653.3" "653.3"
          "1966:Q3" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "650.7" "649.9" "649.9" "654.8" "654.8" "654.8" "654.8" "659.5" "659.5" "659.5" "659.5"
          "1966:Q4" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "657.0" "657.2" "661.1" "661.1" "661.1" "661.1" "667.1" "667.1" "667.1" "667.1"
          "1967:Q1" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "657.2" "660.7" "660.7" "660.7" "660.7" "665.7" "665.7" "665.7" "665.7"
          "1967:Q2" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "664.6" "664.7" "664.7" "664.7" "669.2" "669.2" "669.2" "669.2"
          "1967:Q3" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "671.6" "672.0" "672.0" "675.6" "675.6" "675.6" "675.6"
          "1967:Q4" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "679.4" "679.6" "681.8" "681.8" "681.8" "681.8"
          "1968:Q1" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "689.7" "692.7" "692.7" "692.7" "692.7"
          "1968:Q2" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "701.7" "703.4" "703.4" "703.4"
          "1968:Q3" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "712.0" "712.3" "712.3"
          "1968:Q4" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "719.1" "718.4"
          "1969:Q1" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "723.6"
          "1969:Q2" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1969:Q3" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1969:Q4" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1970:Q1" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1970:Q2" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1970:Q3" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1970:Q4" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1971:Q1" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1971:Q2" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1971:Q3" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          "1971:Q4" "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"  "#N/A"
          end
          I hope this helps.
          The main target here is that a shock variable (measured as residual of a given period gdp variable at a given vintage date on the same period gdp variable in a previous vintage date) would be a proxy for the arrival of new information ( that led to the revision of the gdp variable). I hope this clarifies more

          Look forward to hearing

          Comment


          • #6
            Code:
            *** Get data ready
            use "Y:\Statalist\predictionshocks.dta", clear
            gen year = real(substr(date, 1, 4))
            gen quarter = real(substr(date, -1, 1))
            
            gen statadate = yq(year, quarter)
            format statadate %tq
            
            drop date year quarter
            order statadate, first
            rename statadate date
            
            destring routput*, force replace
            
            *** Reshape
            local predictdate = 1
            foreach var of varlist routput* {
                rename `var' routput`predictdate'
                local predictdate = `predictdate' + 1
            }
            reshape long routput, i(date) j(prediction)
            
            *** Regress
            xtset date prediction
            reg routput L.routput
            predict shock, r
            Is this what you are looking for? In the first part I transform the string date to a date Stata understands. Then in the reshape part, I rename the predictions because the reshape command requires sequential variables (e.g. var1 var2, not var23q4 var24q1). Then finally we regress each routput on the output from the previous vintage and generate the shock variable as the residual from that regression.

            Comment


            • #7
              Jesse: Thanks a lot.
              I have some questions:
              1- I have done what you suggested and I have estimated the residuals now (shocks). The output looks like:
              ----------------------- copy starting from the next line -----------------------
              Code:
              * Example generated by -dataex-. To install: ssc install dataex
              clear
              input float date int prediction double routput float shock
              -52   1  306.4          .
              -52   2  306.4  -13.73682
              -52   3  306.4  -13.73682
              -52   4  306.4  -13.73682
              -52   5  306.4  -13.73682
              -52   6  306.4  -13.73682
              -52   7  306.4  -13.73682
              -52   8  306.4  -13.73682
              -52   9  306.4  -13.73682
              -52  10  306.4  -13.73682
              -52  11  306.4  -13.73682
              -52  12  306.4  -13.73682
              -52  13  306.4  -13.73682
              -52  14  306.4  -13.73682
              -52  15  306.4  -13.73682
              -52  16  306.4  -13.73682
              -52  17  306.4  -13.73682
              -52  18  306.4  -13.73682
              -52  19  306.4  -13.73682
              -52  20  306.4  -13.73682
              -52  21  306.4  -13.73682
              -52  22  306.4  -13.73682
              -52  23  306.4  -13.73682
              -52  24  306.4  -13.73682
              -52  25  306.4  -13.73682
              -52  26  306.4  -13.73682
              -52  27  306.4  -13.73682
              -52  28  306.4  -13.73682
              -52  29  306.4  -13.73682
              -52  30  306.4  -13.73682
              -52  31  306.4  -13.73682
              -52  32  306.4  -13.73682
              -52  33  306.4  -13.73682
              -52  34  306.4  -13.73682
              -52  35  306.4  -13.73682
              -52  36  306.4  -13.73682
              -52  37  306.4  -13.73682
              -52  38  306.4  -13.73682
              -52  39  306.4  -13.73682
              -52  40  306.4  -13.73682
              -52  41  306.4  -13.73682
              -52  42    464  143.86317
              -52  43    464  -14.29152
              -52  44    464  -14.29152
              -52  45    464  -14.29152
              -52  46    464  -14.29152
              -52  47    464  -14.29152
              -52  48    464  -14.29152
              -52  49    464  -14.29152
              -52  50    464  -14.29152
              -52  51    464  -14.29152
              -52  52    464  -14.29152
              -52  53    464  -14.29152
              -52  54    464  -14.29152
              -52  55    464  -14.29152
              -52  56    464  -14.29152
              -52  57    464  -14.29152
              -52  58    464  -14.29152
              -52  59    464  -14.29152
              -52  60    464  -14.29152
              -52  61    464  -14.29152
              -52  62    466  -12.29152
              -52  63    466 -14.298558
              -52  64    466 -14.298558
              -52  65    466 -14.298558
              -52  66    466 -14.298558
              -52  67    466 -14.298558
              -52  68    466 -14.298558
              -52  69    466 -14.298558
              -52  70    466 -14.298558
              -52  71    466 -14.298558
              -52  72    466 -14.298558
              -52  73    466 -14.298558
              -52  74    466 -14.298558
              -52  75    466 -14.298558
              -52  76    466 -14.298558
              -52  77    466 -14.298558
              -52  78    466 -14.298558
              -52  79    466 -14.298558
              -52  80    466 -14.298558
              -52  81    466 -14.298558
              -52  82 1056.5   576.2014
              -52  83 1056.5 -16.376917
              -52  84 1056.5 -16.376917
              -52  85 1056.5 -16.376917
              -52  86 1056.5 -16.376917
              -52  87 1056.5 -16.376917
              -52  88 1056.5 -16.376917
              -52  89 1056.5 -16.376917
              -52  90 1056.5 -16.376917
              -52  91 1056.5 -16.376917
              -52  92 1056.5 -16.376917
              -52  93 1056.5 -16.376917
              -52  94 1056.5 -16.376917
              -52  95 1056.5 -16.376917
              -52  96 1056.5 -16.376917
              -52  97 1056.5 -16.376917
              -52  98 1056.5 -16.376917
              -52  99 1056.5 -16.376917
              -52 100 1056.5 -16.376917
              end
              format %tq date

              My first questions is: If I am interested in shocks at a particular vintage (which is vintage of year 2015 quarter 3) to proxy for the arrival of new information as of that particular vintage date, where I can find those? does the predictdate in your code represent the vintage date? if so, what would be the vintage date of year 2015 quarter 3?

              I will need to extract vintage 2015 Q3 shocks in all gdp variables and reshape my data to be ready for merging with other economic dataset.
              The ultimate objective would be to use these shocks as proxies for information arrival in year 2015 quarter 3. Therefore, using all vintages initially was meant to estimate the vintage shocks. Now, I need to use shocks of the year 2015 q3 vintage that manifest in a revision of all gdp variables in all my sample. Does that make sense to you?

              i think the steps should be something like:

              Extract shocks of all gdp data variables in my sample as pertaining to a vintage date of year 2015 quarter 3 and drop all other shocks pertaining to the remaining vintages
              then, reshape back again those shocks of year 2015 quarter 3, so data becomes ready for merging.

              Can you help me in that please?

              Thanks













              Last edited by Lisa Wilson; 19 Oct 2016, 10:23.

              Comment


              • #8
                Hi

                There's no 2015Q3 vintage in the sample you attached, so you'll have to figure out which predictdate it relates to. Then you can simply add

                Code:
                keep if predictdate == <2015q3date>
                And you would have what you want I think?

                Comment


                • #9
                  Hi
                  The output has a variable called prediction and not predectdate. Do you know how to figure out the 2015Q3 vintage?
                  In my complete dataset (not the one in dataex) this vintage variable is routput15q3

                  is there anyway to extract only shocks pertaining to this vintage and then reshape my data to be ready for merging?

                  Comment


                  • #10
                    Ah yes, I called it prediction, not predictdate, my bad! I've added a line of code that now tells you which vintage relates to which prediction number.

                    E.g. "routput68q3 became routput12" means prediction 12 relates to 68Q3.

                    There's probably a better way to do this, but it's non-trivial AFAIK.

                    Code:
                    *** Get data ready
                    use "Y:\Statalist\predictionshocks.dta", clear
                    gen year = real(substr(date, 1, 4))
                    gen quarter = real(substr(date, -1, 1))
                    
                    gen statadate = yq(year, quarter)
                    format statadate %tq
                    
                    drop date year quarter
                    order statadate, first
                    rename statadate date
                    
                    destring routput*, force replace
                    
                    *** Reshape
                    local predictdate = 1
                    foreach var of varlist routput* {
                        di "`var' became routput`predictdate'"
                        rename `var' routput`predictdate'
                        local predictdate = `predictdate' + 1
                    }
                    reshape long routput, i(date) j(prediction)
                    
                    *** Regress
                    xtset date prediction
                    reg routput L.routput
                    predict shock, r

                    Comment


                    • #11
                      Hi Jesse
                      Many many thanks. That seems to be helpful.

                      I followed your suggestions:
                      I got the following stata output:

                      Code:
                      routput65q4 became routput1
                      routput66q1 became routput2
                      routput66q2 became routput3
                      routput66q3 became routput4
                      routput66q4 became routput5
                      routput67q1 became routput6
                      routput67q2 became routput7
                      routput67q3 became routput8
                      routput67q4 became routput9
                      routput68q1 became routput10
                      routput68q2 became routput11
                      routput68q3 became routput12
                      routput68q4 became routput13
                      routput69q1 became routput14
                      routput69q2 became routput15
                      routput69q3 became routput16
                      routput69q4 became routput17
                      routput70q1 became routput18
                      routput70q2 became routput19
                      routput70q3 became routput20
                      routput70q4 became routput21
                      routput71q1 became routput22
                      routput71q2 became routput23
                      routput71q3 became routput24
                      routput71q4 became routput25
                      routput72q1 became routput26
                      routput72q2 became routput27
                      routput72q3 became routput28
                      routput72q4 became routput29
                      routput73q1 became routput30
                      routput73q2 became routput31
                      routput73q3 became routput32
                      routput73q4 became routput33
                      routput74q1 became routput34
                      routput74q2 became routput35
                      routput74q3 became routput36
                      routput74q4 became routput37
                      routput75q1 became routput38
                      routput75q2 became routput39
                      routput75q3 became routput40
                      routput75q4 became routput41
                      routput76q1 became routput42
                      routput76q2 became routput43
                      routput76q3 became routput44
                      routput76q4 became routput45
                      routput77q1 became routput46
                      routput77q2 became routput47
                      routput77q3 became routput48
                      routput77q4 became routput49
                      routput78q1 became routput50
                      routput78q2 became routput51
                      routput78q3 became routput52
                      routput78q4 became routput53
                      routput79q1 became routput54
                      routput79q2 became routput55
                      routput79q3 became routput56
                      routput79q4 became routput57
                      routput80q1 became routput58
                      routput80q2 became routput59
                      routput80q3 became routput60
                      routput80q4 became routput61
                      routput81q1 became routput62
                      routput81q2 became routput63
                      routput81q3 became routput64
                      routput81q4 became routput65
                      routput82q1 became routput66
                      routput82q2 became routput67
                      routput82q3 became routput68
                      routput82q4 became routput69
                      routput83q1 became routput70
                      routput83q2 became routput71
                      routput83q3 became routput72
                      routput83q4 became routput73
                      routput84q1 became routput74
                      routput84q2 became routput75
                      routput84q3 became routput76
                      routput84q4 became routput77
                      routput85q1 became routput78
                      routput85q2 became routput79
                      routput85q3 became routput80
                      routput85q4 became routput81
                      routput86q1 became routput82
                      routput86q2 became routput83
                      routput86q3 became routput84
                      routput86q4 became routput85
                      routput87q1 became routput86
                      routput87q2 became routput87
                      routput87q3 became routput88
                      routput87q4 became routput89
                      routput88q1 became routput90
                      routput88q2 became routput91
                      routput88q3 became routput92
                      routput88q4 became routput93
                      routput89q1 became routput94
                      routput89q2 became routput95
                      routput89q3 became routput96
                      routput89q4 became routput97
                      routput90q1 became routput98
                      routput90q2 became routput99
                      routput90q3 became routput100
                      routput90q4 became routput101
                      routput91q1 became routput102
                      routput91q2 became routput103
                      routput91q3 became routput104
                      routput91q4 became routput105
                      routput92q1 became routput106
                      routput92q2 became routput107
                      routput92q3 became routput108
                      routput92q4 became routput109
                      routput93q1 became routput110
                      routput93q2 became routput111
                      routput93q3 became routput112
                      routput93q4 became routput113
                      routput94q1 became routput114
                      routput94q2 became routput115
                      routput94q3 became routput116
                      routput94q4 became routput117
                      routput95q1 became routput118
                      routput95q2 became routput119
                      routput95q3 became routput120
                      routput95q4 became routput121
                      routput96q1 became routput122
                      routput96q2 became routput123
                      routput96q3 became routput124
                      routput96q4 became routput125
                      routput97q1 became routput126
                      routput97q2 became routput127
                      routput97q3 became routput128
                      routput97q4 became routput129
                      routput98q1 became routput130
                      routput98q2 became routput131
                      routput98q3 became routput132
                      routput98q4 became routput133
                      routput99q1 became routput134
                      routput99q2 became routput135
                      routput99q3 became routput136
                      routput99q4 became routput137
                      routput00q1 became routput138
                      routput00q2 became routput139
                      routput00q3 became routput140
                      routput00q4 became routput141
                      routput01q1 became routput142
                      routput01q2 became routput143
                      routput01q3 became routput144
                      routput01q4 became routput145
                      routput02q1 became routput146
                      routput02q2 became routput147
                      routput02q3 became routput148
                      routput02q4 became routput149
                      routput03q1 became routput150
                      routput03q2 became routput151
                      routput03q3 became routput152
                      routput03q4 became routput153
                      routput04q1 became routput154
                      routput04q2 became routput155
                      routput04q3 became routput156
                      routput04q4 became routput157
                      routput05q1 became routput158
                      routput05q2 became routput159
                      routput05q3 became routput160
                      routput05q4 became routput161
                      routput06q1 became routput162
                      routput06q2 became routput163
                      routput06q3 became routput164
                      routput06q4 became routput165
                      routput07q1 became routput166
                      routput07q2 became routput167
                      routput07q3 became routput168
                      routput07q4 became routput169
                      routput08q1 became routput170
                      routput08q2 became routput171
                      routput08q3 became routput172
                      routput08q4 became routput173
                      routput09q1 became routput174
                      routput09q2 became routput175
                      routput09q3 became routput176
                      routput09q4 became routput177
                      routput10q1 became routput178
                      routput10q2 became routput179
                      routput10q3 became routput180
                      routput10q4 became routput181
                      routput11q1 became routput182
                      routput11q2 became routput183
                      routput11q3 became routput184
                      routput11q4 became routput185
                      routput12q1 became routput186
                      routput12q2 became routput187
                      routput12q3 became routput188
                      routput12q4 became routput189
                      routput13q1 became routput190
                      routput13q2 became routput191
                      routput13q3 became routput192
                      routput13q4 became routput193
                      routput14q1 became routput194
                      routput14q2 became routput195
                      routput14q3 became routput196
                      routput14q4 became routput197
                      routput15q1 became routput198
                      routput15q2 became routput199
                      routput15q3 became routput200
                      routput15q4 became routput201
                      routput16q1 became routput202
                      routput16q2 became routput203
                      routput16q3 became routput204
                      I then identified prediction 200 to be the shocks pertaining to vintage 2015 quarter 3 ( as estimated from regressions of two subsequent vintages as we know)

                      I then did the following:
                      Code:
                      keep if prediction==200
                      tsset date
                      I got the following as an example from dataex;
                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input float date int prediction double routput float shockVi
                      -52 200 1934.5 -19.467176
                      -51 200 1932.3 -19.459435
                      -50 200 1930.3 -19.452394
                      -49 200 1960.7 -19.559393
                      -48 200 1989.5  -19.66076
                      -47 200 2021.9 -19.774796
                      -46 200 2033.2  -19.81457
                      -45 200 2035.3  -19.82196
                      -44 200 2007.5  -19.72411
                      -43 200 2000.8  -19.70053
                      -42 200 2022.8 -19.777964
                      -41 200 2004.7 -19.714256
                      -40 200 2084.6  -19.99548
                      -39 200 2147.6 -20.217216
                      -38 200 2230.4 -20.508644
                      -37 200 2273.4  -20.65999
                      -36 200 2304.5  -20.76945
                      -35 200 2344.5 -20.910236
                      -34 200 2392.8 -21.080236
                      -33 200 2398.1  -21.09889
                      -32 200 2423.5  -21.18829
                      -31 200 2428.5  -21.20589
                      -30 200 2446.1 -21.267834
                      -29 200 2526.4  -21.55046
                      -28 200 2573.4 -21.715887
                      -27 200 2593.5  -21.78663
                      -26 200 2578.9 -21.735245
                      -25 200 2539.8 -21.597626
                      -24 200   2528 -21.556095
                      -23 200 2530.7   -21.5656
                      -22 200 2559.4  -21.66661
                      -21 200 2609.3 -21.842243
                      -20 200 2683.8  -22.10446
                      -19 200 2727.5 -22.258266
                      -18 200 2764.1 -22.387085
                      -17 200 2780.8 -22.445864
                      -16 200   2770  -22.40785
                      -15 200 2792.9  -22.48845
                      -14 200 2790.6 -22.480356
                      -13 200 2836.2 -22.640854
                      -12 200 2854.5 -22.705263
                      -11 200 2848.2  -22.68309
                      -10 200 2875.9 -22.780584
                       -9 200 2846.4 -22.676754
                       -8 200 2772.7 -22.417355
                       -7 200 2790.9 -22.481413
                       -6 200 2855.5  -22.70878
                       -5 200 2922.3 -22.943895
                       -4 200 2976.6 -23.135014
                       -3 200   3049  -23.38984
                       -2 200 3043.1  -23.36907
                       -1 200 3055.1 -23.411306
                        0 200 3123.2 -23.650995
                        1 200 3111.3  -23.60911
                        2 200 3119.1 -23.636564
                        3 200 3081.3  -23.50352
                        4 200 3102.3 -23.577435
                        5 200 3159.9 -23.780167
                        6 200 3212.6  -23.96565
                        7 200 3277.7  -24.19478
                        8 200 3336.8 -24.402794
                        9 200 3372.7  -24.52915
                       10 200 3404.8  -24.64213
                       11 200   3418  -24.68859
                       12 200 3456.1  -24.82269
                       13 200 3501.1 -24.981073
                       14 200 3569.5  -25.22182
                       15 200   3595  -25.31157
                       16 200 3672.7 -25.585047
                       17 200 3716.4  -25.73886
                       18 200 3766.9   -25.9166
                       19 200 3780.2  -25.96341
                       20 200 3873.5 -26.291796
                       21 200 3926.4 -26.477985
                       22 200 4006.2 -26.758854
                       23 200 4100.6  -27.09111
                       24 200 4201.9  -27.44765
                       25 200 4219.1  -27.50819
                       26 200 4249.2  -27.61413
                       27 200 4285.6 -27.742247
                       28 200 4324.9  -27.88057
                       29 200 4328.7 -27.893944
                       30 200 4366.1  -28.02558
                       31 200 4401.2  -28.14912
                       32 200 4490.6 -28.463776
                       33 200 4566.4 -28.730566
                       34 200 4599.3 -28.846363
                       35 200 4619.8 -28.918516
                       36 200 4691.6 -29.171227
                       37 200 4706.7 -29.224375
                       38 200 4736.1  -29.32785
                       39 200 4715.5  -29.25535
                       40 200 4707.1  -29.22578
                       41 200 4715.4 -29.254995
                       42 200 4757.2 -29.402117
                       43 200 4708.3 -29.230005
                       44 200 4834.3 -29.673483
                       45 200 4861.9 -29.770626
                       46 200   4900 -29.904724
                       47 200 4914.3 -29.955055
                      end
                      format %tq date

                      I think the shocks are now ready for merging and I do not need to reshape the data, correct ?

                      Comment


                      • #12
                        I think so, yes. Just be careful if you were to run this again with different data, as 15q3 might no longer correspond to prediction 200. Of course, if its possible, you will always want to do a manual check/eyeball it to verify you're getting what you intended.

                        Comment


                        • #13
                          Thanks a lot. I gave you "Likes"
                          Jesse, I noted that some regressions may not have enough observations because some gdp data would be missing ( an obvious example would be gdp variable of, say, quarter 4 year 1990 in a previous vintage date , say year 1990 quarter 3 or 1990 quarter 2 and so on)
                          Can you adjust your code to be restricted to regressions with a certain number of observations, for example 20 obs?

                          Comment


                          • #14
                            Haha, thanks :D

                            At the moment there's just one regression, i.e. all the info is pooled to estimate one coefficient. So I don't know if it'd be a good idea to avoid short timeframes? Unless you want to perform separate regressions per gdp date?

                            Comment


                            • #15
                              Hi Jesse
                              Well, yes that is what I wanted initially. I should have been clear about that. Sorry!
                              I want the regression to be estimated per each gdp data (not vintage date), so time series regressions. It will make more sense to regress the gdp variable in a given vintage date on the same gdp variable but at a previous vintage date on a time series basis without pooling all data. This might give better results.

                              Is this possible?

                              Comment

                              Working...
                              X