Announcement

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

  • How to make Graph for Seasonality Data

    Dear Statlist,

    ​I am trying to make figure for seasonality data. I have households cross-section data over 5 quarters of two years, e.g. two quarter of 2012 and three quarter of 2013 ( each quarter have 2800 households). My purpose is with 5 variables (i.e. in case 5 products) which indicate the quantity consumed of households over seasons to show seasonality on quantity consumption of households during season.

    I have followed the this journal
    PHP Code:
    http://www.stata-journal.com/sjpdf.html?articlenum=gr0025 
    however still didn't get the point how to do it.

    I am sorry for my ​inconvenience but I high appreciate if someone could to give me idea, how to show these seasonality quantity food -consumed in Stata?

    More less, I would like to do somehow similar to this figures:

    Click image for larger version

Name:	sd.jpg
Views:	1
Size:	131.7 KB
ID:	1331413



    or

    Click image for larger version

Name:	FDXCU[1].png
Views:	1
Size:	4.6 KB
ID:	1331412






    Thank you in advance



  • #2
    Your URL doesn't work. Here it is again: http://www.stata-journal.com/sjpdf.h...iclenum=gr0025

    Are these weekly data? Can you post sample data? Stata weeks don't usually match any outside definition of week.

    Comment


    • #3
      Dear Nick

      ​Thank you so much

      Data are quarterly across 2800 households, something like that:
      Code:
         
      hhid time w1 w2 w3 w4 w5
      1 22012 0,15 0,08 0,04 0,08 0,03
      2 22012 0,24 0,17 0,06 0,11 0,03
      3 22012 0,12 0,14 0,01 0,10 0,00
      4 22012 0,15 0,06 0,03 0,05 0,00
      . 22012 0,19 0,11 0,05 0,09 0,06
      . 22012 0,21 0,11 0,03 0,08 0,06
      . 22012 0,11 0,03 0,05 0,13 0,04
      2800 22012 0,22 0,04 0,00 0,10 0,04
      1 32012 0,23 0,10 0,04 0,10 0,04
      2 32012 0,13 0,04 0,01 0,02 0,02
      3 32012 0,18 0,07 0,04 0,11 0,12
      4 32012 0,20 0,07 0,02 0,09 0,05
      . 32012 0,15 0,06 0,03 0,07 0,02
      . 32012 0,21 0,11 0,04 0,07 0,07
      . 32012 0,27 0,09 0,06 0,11 0,01
      2800 32012 0,21 0,10 0,04 0,09 0,06
      1 12013 0,22 0,15 0,01 0,08 0,04
      2 12013 0,17 0,12 0,04 0,07 0,07
      3 12013 0,15 0,08 0,01 0,06 0,04
      4 12013 0,22 0,12 0,00 0,09 0,00
      . 12013 0,25 0,12 0,10 0,07 0,00
      . 12013 0,25 0,07 0,02 0,09 0,02
      . 12013 0,22 0,17 0,05 0,09 0,06
      2800 12013 0,12 0,05 0,03 0,04 0,07
      1 22013 0,05 0,07 0,01 0,03 0,00
      2 22013 0,14 0,07 0,03 0,04 0,04
      3 22013 0,36 0,08 0,02 0,04 0,07
      4 22013 0,26 0,14 0,02 0,05 0,05
      . 22013 0,06 0,04 0,02 0,01 0,02
      . 22013 0,05 0,12 0,03 0,06 0,05
      . 22013 0,06 0,11 0,03 0,02 0,04
      2800 22013 0,16 0,07 0,02 0,09 0,02
      1 42013 0,06 0,05 0,03 0,01 0,03
      2 42013 0,09 0,05 0,00 0,03 0,03
      3 42013 0,01 0,02 0,00 0,00 0,01
      4 42013 0,23 0,02 0,05 0,10 0,17
      . 42013 0,10 0,06 0,05 0,10 0,00
      . 42013 0,14 0,08 0,02 0,09 0,02
      . 42013 0,16 0,03 0,03 0,12 0,08
      2800 42013 0,15 0,03 0,03 0,11 0,23

      thanks

      Comment


      • #4
        In my opinion, you can use Acf (auto correlation funtion) for checking the seasonality of your data. If your dataset has a strong seasonality, it will show you clearly in ACF as sin-cosin shape, and damped over time. If not, that means the seasonality of your dataset is not clear, and of course harder to examine or predict

        Comment


        • #5
          Can you explain about your variable:time,w1-w5?

          Comment


          • #6
            Dear Thong
            ​thank you

            time is quarter data, i.e. 22012 across 2800 households and the same for other quarters, and w1-w5 is consumed products, I want to see (to show) seasonality of household consumption for each these 5 products over time(quarters) across households (each quarter have 2800 households)

            Thank you

            Comment


            • #7
              I try to use ACF and I am getting this error
              Code:
                sample may not include multiple panels
              r(459);

              Comment


              • #8
                Originally posted by David Achiles View Post
                Dear Thong
                ​thank you

                time is quarter data, i.e. 22012 across 2800 households and the same for other quarters, and w1-w5 is consumed products, I want to see (to show) seasonality of household consumption for each these 5 products over time(quarters) across households (each quarter have 2800 households)

                Thank you
                Dear David,
                Firstly, you have to set up your quarterly data in the format of time series before graphing it. The format for your variable time will be 20001q1 2001q2 and so on. However, I don't know the meaning of the code of time variable. For instance, 22012 and 32012, what does it mean? I guess it refers to 2012q1, 2012q2 (the first and second quarter of the year 2012), am I right?

                Comment


                • #9
                  You are right, sorry for unclear describing but it is 22012==2012q2; 32012==2012q3; 12013==2013q1; 22013==2013q2; and 42013==2013q4

                  ​Also I have already used tsset corresponding to quarterly data

                  Comment


                  • #10
                    Sorry David, I am not familiar with procedure on how to convert your raw variable time to format of quarterly data. I can figure it out, but I need more time. However, if you can do it, (please show me how you do it, I want to learn from you ^^). Next, I am going to show you the next step.
                    tsset time, quarterly
                    tsline w1 if hhid==1 and so on
                    Because, tsline command does not allow you to use by(option).

                    And as I mentioned above, you can use acf w1 for identifying your variable has seasonality or not. as the photo attached here
                    Attached Files

                    Comment


                    • #11
                      I think this is the code for you
                      Firstly, you need to change the time variable from numeric format to string format and recode it by the following codes
                      Code:
                      tostring time, replace format(%20.0f)
                      gen quarter=real(substr(time,1,1))
                      gen year=real(substr(time,2,4))
                      gen quarterly_date=yq(year, quarter)
                      format quarterly_date %tq
                      tab quarterly_date

                      Comment


                      • #12
                        Code:
                        . list
                        
                             +-------------------------------------------------------------+
                             | hhid    time    w1    w2    w3    w4    w5   quarter   year |
                             |-------------------------------------------------------------|
                          1. |    1   22012   .15   .08   .04   .08   .03         2   2012 |
                          2. |    2   22012   .24   .17   .06   .11   .03         2   2012 |
                          3. |    3   22012   .12   .14   .01    .1     0         2   2012 |
                          4. |    4   22012   .15   .06   .03   .05     0         2   2012 |
                          5. |    5   22012   .19   .11   .05   .09   .06         2   2012 |
                             |-------------------------------------------------------------|
                          6. |    6   22012   .21   .11   .03   .08   .06         2   2012 |
                          7. |    7   22012   .11   .03   .05   .13   .04         2   2012 |
                             +-------------------------------------------------------------+
                        
                        . des
                        
                        Contains data
                          obs:             7                          
                         vars:            10                          
                         size:           287                          
                        ---------------------------------------------------------------------------------------------------------------------------------------------
                                      storage   display    value
                        variable name   type    format     label      variable label
                        ---------------------------------------------------------------------------------------------------------------------------------------------
                        hhid            float   %9.0g                 
                        time            str5    %9s                   
                        w1              float   %9.0g                 
                        w2              float   %9.0g                 
                        w3              float   %9.0g                 
                        w4              float   %9.0g                 
                        w5              float   %9.0g                 
                        quarter         float   %9.0g                 
                        year            float   %9.0g                 
                        quarterly_date  float   %tq                   
                        ---------------------------------------------------------------------------------------------------------------------------------------------
                        Sorted by:  
                             Note:  dataset has changed since last saved
                        
                        
                        
                        . list
                        
                             +------------------------------------------------------------------------+
                             | hhid    time    w1    w2    w3    w4    w5   quarter   year   quarte~e |
                             |------------------------------------------------------------------------|
                          1. |    1   22012   .15   .08   .04   .08   .03         2   2012     2012q2 |
                          2. |    2   22012   .24   .17   .06   .11   .03         2   2012     2012q2 |
                          3. |    3   22012   .12   .14   .01    .1     0         2   2012     2012q2 |
                          4. |    4   22012   .15   .06   .03   .05     0         2   2012     2012q2 |
                          5. |    5   22012   .19   .11   .05   .09   .06         2   2012     2012q2 |
                             |------------------------------------------------------------------------|
                          6. |    6   22012   .21   .11   .03   .08   .06         2   2012     2012q2 |
                          7. |    7   22012   .11   .03   .05   .13   .04         2   2012     2012q2 |
                             +------------------------------------------------------------------------+
                        Hope it helps!

                        Comment


                        • #13
                          Dear Thong

                          ​Thank you so much , I highly appreciate it

                          Comment


                          • #14
                            You should create quarterly_date variable, and do the following things.
                            Maybe, you should create some variabels as total of w1 for all households you have in the dataset (if it is what you want) by the following codes. And then using these codes.
                            Code:
                            . egen total_w1=total(w1)
                            
                            . egen total_w1_1_10=total(w1) if hhid<=10
                            (14990 missing values generated)
                            
                            . tab1 total_w1 total_w1_1_10
                            
                            -> tabulation of total_w1  
                            
                               total_w1 |      Freq.     Percent        Cum.
                            ------------+-----------------------------------
                               2894.133 |     15,000      100.00      100.00
                            ------------+-----------------------------------
                                  Total |     15,000      100.00
                            
                            -> tabulation of total_w1_1_10  
                            
                            total_w1_1_ |
                                     10 |      Freq.     Percent        Cum.
                            ------------+-----------------------------------
                               1.756811 |         10      100.00      100.00
                            ------------+-----------------------------------
                                  Total |         10      100.00
                            
                            . list hhid total_w1_1_10 w1 in 1/10
                            
                                 +----------------------------+
                                 | hhid   total~10         w1 |
                                 |----------------------------|
                              1. |    1   1.756811   .1513982 |
                              2. |    2   1.756811   .2389566 |
                              3. |    3   1.756811   .1210539 |
                              4. |    4   1.756811   .1536625 |
                              5. |    5   1.756811   .1888267 |
                                 |----------------------------|
                              6. |    6   1.756811   .2120228 |
                              7. |    7   1.756811   .1139096 |
                              8. |    8   1.756811   .2181637 |
                              9. |    9   1.756811   .2258199 |
                             10. |   10   1.756811   .1329967 |
                                 +----------------------------+
                            
                            
                            
                            
                            . dis .1513982+.2389566+.1210539+.1536625+.1888267+.2120228 +.1139096+.2181637+.2258199 +.1329967
                            1.7568106
                            
                            tsset quarterly_date
                            tsline total_w1
                            acf total_w1, lag(#lags) #lags=your Quarterly points you have/4. For instance, if you have 180 quarterly points in your sample, # lags=180/4=45.
                            But I concern that you have only 5 quarters, and it will be hard to find out any seasonality during limited dataset!

                            Comment


                            • #15
                              Returning to the first post:

                              You have panel data, so possible plots include (for one or more variables)

                              1. A composite plot of all panels against calendar time. Possibly a mess but a collective pattern might be obvious.

                              2. Some kind of average across panels against calendar time.

                              3. #1 but against quarter of the year 1 2 3 4.

                              4. #2 but against quarter of the year.

                              Note that cycleplot (SSC) doesn't apply directly to quarterly data.

                              Comment

                              Working...
                              X