Announcement

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

  • Creating dataset of GDP growth forecasts

    Dear all,

    I am enlisting your help once again.
    For a paper we are currently working on, we would like to include GDP growth forecasts as published in the IMF's World Economic Outlook (WEO) in our econometric model.
    I have found such a database exists; in attachment you can find the selection of countries in scope of our analysis.

    Now, one practical problem with how this database is constructed, for our purposes at least, is that it uses each WEO as ‘starting point’ (= column) and that hence the ‘interpretation’ of each year (= row) depends on which WEO is selected. For example, row 6 in attachment is a t+2 forecast for both WEO’s of 1990 (column C and D), a t+1 forecast for both WEO’s of 1991 (column E and F), etc.
    Also attached you can find an example of what we would be working towards.

    Is there anyone who could give some advice on how to easily transform this dataset towards the format we need, preferably in Stata but if someone know how to do this in Excel, please also feel free to provide your suggestions. :-)

    I hope I am making myself somewhat clear. If not, please indicate and I will try to explain better.

    Thank you in advance!

    Willem


    Attached Files

  • #2
    Dear Willem,

    The following lines should do what you want. By looping over the horizon (`hor'), the publication (`pub' = {spring, fall}) and the year (`tt'), the code copies the GDP forecast for `tt'+`hor' published in `pub' of year `tt' to gdp_forecast`hor'_`pub' [tt]. By one iteration, the copying is done for all countries and one specific combination of horizon, publication and year.

    Note that I first destring the value columns and define the data set as panel to make use of time series operators.

    Code:
    import excel "IMF nowcasts (selection).xlsx", clear sheet("IMF nowcast") firstrow
    
    * Destring value columns
    ds country year, not
    foreach vv in `r(varlist)' {
        qui destring `vv', replace force
    }
    
    * Define as panel data set
    encode country, gen(countryID)
    xtset countryID year
    
    * Copy forecasts
    forval hor=1/3 {
        foreach pub in S F {
            * Create empty variable
            qui gen gdp_forecast`hor'_`pub' = .
            forval tt=1990/2020 {
                * Copy GDP forecast for t+h published in spring/fall of year t
                replace gdp_forecast`hor'_`pub' = F`hor'.`pub'`tt'ngdp_rpch if year==`tt'
            }
        }
    }
    
    rename *_S *_spring
    rename *_F *_fall
    Best,
    Christopher

    Comment


    • #3
      Attachments are deprecated here on this forum for security purposes. It's better to post an example of your data using dataex (see the FAQ for details). I took a look at the IMF nowcast sheet. It looks like you'll want to reshape the data and then remove the missing values. From there I'm not entirely sure how to proceed because I don't understand what I'm looking at, but hopefully this is a starting point.

      Code:
      import excel using "IMF nowcasts (selection).xlsx", firstrow clear 
      
      
      ds country year, not 
      destring `r(varlist)', replace 
      
      
      reshape long F S, i(country year) j(some_var)string
      keep if !mi(S, F)
      
      list in 1/10, noobs
       +--------------------------------------------------------+
        | country   year        some_var           S           F |
        |--------------------------------------------------------|
        | Austria   1988   1990ngdp_rpch   4.1641563   4.1641563 |
        | Austria   1989   1990ngdp_rpch   3.9567176   3.7895445 |
        | Austria   1989   1991ngdp_rpch   3.7895445   3.7328241 |
        | Austria   1990   1990ngdp_rpch    3.100001   3.2930107 |
        | Austria   1990   1991ngdp_rpch   3.2930107   4.3786142 |
        |--------------------------------------------------------|
        | Austria   1990   1992ngdp_rpch   4.3786142   4.3786142 |
        | Austria   1991   1990ngdp_rpch   2.5040069   2.9377434 |
        | Austria   1991   1991ngdp_rpch   2.9377434   3.1929951 |
        | Austria   1991   1992ngdp_rpch   3.1929951   3.1929951 |
        | Austria   1991   1993ngdp_rpch    2.976418    2.976418 |
        +--------------------------------------------------------+

      Comment


      • #4
        Originally posted by Christopher Zuber View Post
        Dear Willem,

        The following lines should do what you want. By looping over the horizon (`hor'), the publication (`pub' = {spring, fall}) and the year (`tt'), the code copies the GDP forecast for `tt'+`hor' published in `pub' of year `tt' to gdp_forecast`hor'_`pub' [tt]. By one iteration, the copying is done for all countries and one specific combination of horizon, publication and year.

        Note that I first destring the value columns and define the data set as panel to make use of time series operators.

        Code:
        import excel "IMF nowcasts (selection).xlsx", clear sheet("IMF nowcast") firstrow
        
        * Destring value columns
        ds country year, not
        foreach vv in `r(varlist)' {
        qui destring `vv', replace force
        }
        
        * Define as panel data set
        encode country, gen(countryID)
        xtset countryID year
        
        * Copy forecasts
        forval hor=1/3 {
        foreach pub in S F {
        * Create empty variable
        qui gen gdp_forecast`hor'_`pub' = .
        forval tt=1990/2020 {
        * Copy GDP forecast for t+h published in spring/fall of year t
        replace gdp_forecast`hor'_`pub' = F`hor'.`pub'`tt'ngdp_rpch if year==`tt'
        }
        }
        }
        
        rename *_S *_spring
        rename *_F *_fall
        Best,
        Christopher
        Dear Christopher,

        Thank you very much for this input!
        Only needed to change the following things:
        • Change horizon from 1-3 years to 1-5 years
        • use lowercase for 's' and 'f' for Spring and Fall
        Really saved us a lot of time, so much appreciated!

        Kind regards,

        Willem

        Comment


        • #5
          Dear Willem,

          Nice that the code runs smoothly and thank you for the feedback. In the past, I worked with similar data. I am looking forward to your paper.

          Kind regards,
          Christopher

          Comment

          Working...
          X