Announcement

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

  • BB Algorithm

    Hello everyone,

    First, I'm not a native english speaker so sorry in advance for my mistakes. I hope you could understand me.

    I look for peak and trough of a business cycle. To do that, I would like implement a BB algorithm used by Harding and Pagan in order to identify the turning point in the log level of the gdp serie. For information, I have 44 countries and quarterly observations from 1960 to 2007. Hence, I use at least 5 quarters for a complete cycle and 2 quarters for a phase.

    The only link I found about the implementation is the following one : http://fmwww.bc.edu/repec/bocode/s/sbbq.ado but I do not understand the code.

    I hope someone could help me to understand it or make suggestion about another way to implement the algorithm.

    Thank you in advance,
    Kenza.

  • #2
    I finally found the related package in Stata. My bad. Sorry.

    Kenza.

    Comment


    • #3
      Welcome to Statalist, Kenza! I'm glad you solved your problem. If you haven't read the FAQ yet, please do so. FAQ #13 asks for precise literature references (just authors names isn't much to go on). FAQ #16 asks you to close threads informatively. Here, what related package are you referring to?

      Steve
      Steve Samuels
      Statistical Consulting
      [email protected]

      Stata 14.2

      Comment


      • #4
        Hello,

        Sorry to have forget this point. I will read more in detail the FAQ.

        ​I install the Stata package called "sbbg".

        Unfortunatelly, I still have a problem. I'm supposed to find at least 100-150 peaks and trough in my database but I have only 21. It is as if the algorithm run only for the 3rd first country and not the rest.

        This is the command I have used :

        sort cnt period gdpl
        generate lgdp = log(gdpl)
        sbbq lgdp, window(2) phase(2) cycle(5)


        cnt is the country name, period, the quarter from 1960Q1 to 2007Q4, gdpl is my GDP variable for each countries and each quarter and lgdp is the log of this series.


        My work is based on the IMF's working paper, "How do business cycles and financial cycles interact ?" by Claessens, Kose and Terrones (2011). (https://www.imf.org/external/pubs/ft/wp/2011/wp1188.pdf). For this step, I used exactly the same method than them.


        If anyone have suggestions, i will be glad.

        Comment


        • #5
          I think you want to use the -by- prefix. See -help by-.

          Code:
          bysort cnt (period) : sbbq lgdp, window(2) phase(2) cycle(5)
          You shouldn't need

          Code:
          sort cnt period gdpl
          but only

          Code:
          sort cnt period
          Unnecessary sorting will just consume valuable resources.

          (You can -sort- using the same -by- prefix, as in my example, and that is explained in the help, also.)

          You should:

          1. Read the FAQ carefully.

          2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

          3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

          4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

          Comment


          • #6
            First, thanks you for your answer.

            When I run the sbbq command, a dummy variable (called lgdp_point) is created. It is equal to 1 when there is a peak, -1 when there is a trough and 0 otherwise.

            When I used the by-prefix, an error message r(110) appears, telling me the dummy variable is already defined. Here, the result :

            ----------------------------------------------------------------------------------------------------------------------------
            -> cnt = Argentina
            (8448 missing values generated)
            4 peaks and 3 troughs found

            ----------------------------------------------------------------------------------------------------------------------------
            -> cnt = Australia
            lgdp_point already defined
            r(110);


            Hence, the dummy variable is well defined for the first country but for all the other, the dummy is equal to zero, which I am not supposed to have.

            Another thing seems bizarre, below Argentina, Stata said "8448 missing values generated" whereas no new missing values appears in my dataset and 8448 is the total number of line (192 periods * 44 countries).

            Comment


            • #7
              The -help- states -by- is allowed, but clearly, there's some problem:

              Code:
              clear
              set more off
              
              set obs 100
              
              gen cnt = cond(_n < 40, 1, 2)
              bysort cnt : gen period = 1950 + _n
              
              set seed 3297
              gen somevar = int(runiform()*1000)
              
              * list, sepby(cnt)
              
              bysort cnt (period) : sbbq somevar, window(2) phase(2) cycle(5)
              the error being

              Code:
              -------------------------------------------------------------------------------------------------------
              -> cnt = 1
              (100 missing values generated)
              4 peaks and 5 troughs found
              
              -------------------------------------------------------------------------------------------------------
              -> cnt = 2
              somevar_point already defined
              r(110);
              I'm using

              Code:
              . which sbbq
              /home/roberto/ado/plus/s/sbbq.ado
              *! 1.1 Philippe Bracke 13jan2012
              Try contacting the author at the email address given in the help file (and please let us know how it went).
              You should:

              1. Read the FAQ carefully.

              2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

              3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

              4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

              Comment


              • #8
                Thanks you very much Roberto for your help.

                I will contact the author and give you the feedback.

                Comment


                • #9
                  Hello everybody,

                  I copy-past the answer of the author :

                  " I think the sbbq program cannot be used with the by prefix

                  I would reshape the Stata dataset to have
                  LGDP-country1
                  LGDP-country2
                  as different variables and the I would run sbbq on each one of them

                  If needed you can reshape the dataset again after this, to go back to one country variable and one gdp variable"

                  Before he answer me, I run sbbq command on each country separetely without reshape and it works.

                  Thanks for your help.

                  Comment


                  • #10
                    Kenza,

                    Thanks for the update and for closing the thread.
                    You should:

                    1. Read the FAQ carefully.

                    2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

                    3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

                    4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

                    Comment

                    Working...
                    X