Announcement

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

  • Deseasonalize data

    Hi all,

    Hope everything's fine on your side!
    I have a dataset having as inputs: the id of products, quarters, Year corresponding to quarter, sales, standard units (quantity of units sold) and price. All data are quarterly and in quarterly format:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(idproduct trimestre) double(salesmnf stdunits) float(price Year trimestre_numerico log_sales)
     309 220  549428.8959562927   208530 2.6778486 2015 1 13.216635
     309 221 1657635.6735686143   621990   2.62871 2015 2 14.320903
     309 222 2361742.0307672094   879120  2.787183 2015 3  14.67491
     309 223 2708969.8677070346   982620  2.783677 2015 4  14.81208
     967 184  2396473.630281323    39269  50.12922 2006 1 14.689508
     967 185 2660241.1525705503    57842  49.52799 2006 2 14.793927
     967 186  5219852.680998579   109956   49.0127 2006 3  15.46798
     967 187  7334794.353897563   152567  48.83638 2006 4  15.80814
     967 188  8881935.269550895   178135  50.39701 2007 1  15.99953
     967 189 10233512.188730493   206869  49.77826 2007 2 16.141178
     967 190 11532105.380502779   232399  49.04084 2007 3 16.260645
     967 191 12916953.279701477   262324   48.3155 2007 4 16.374052
     967 192 14688671.884616973   282129  50.49795 2008 1 16.502586
     967 193  15365200.16396829   290896  50.91996 2008 2 16.547615
     967 194 16091061.009136373   292949  52.28841 2008 3 16.593775
     967 195 17345455.968860414   301834  54.58015 2008 4  16.66884
     967 196 18974541.294351768   306890  58.12845 2009 1 16.758608
     967 197  18328205.87957345   288580  58.31976 2009 2 16.723951
     967 198  17651794.01652645   272667  57.03833 2009 3 16.686348
     967 199 17650483.941940885   267862  56.56985 2009 4 16.686274
     967 200  18493158.12872699   258281  58.84344 2010 1 16.732912
     967 201 17992114.925367545   244269  58.63688 2010 2 16.705444
     967 202 16473093.039148297   195666  58.87276 2010 3 16.617239
     967 203 16131722.198414207   181157  60.02505 2010 4 16.596298
     967 204 16433463.564012699   180565  60.16851 2011 1  16.61483
     967 205   16487795.5803066   183904 68.510704 2011 2 16.618132
     967 206  16496828.16649505   187355   73.7523 2011 3  16.61868
     967 207 21155477.203739986   242950  72.24733 2011 4 16.867409
     967 208 23068815.958713137   269471  70.42476 2012 1 16.953993
     967 209 22378351.899928845   263774  80.03603 2012 2 16.923605
     967 210 20671351.806722738   244183  80.17732 2012 3  16.84426
     967 211 22946088.259303723   241641  90.13503 2012 4 16.948658
     967 212 22833179.071655598   241431     78.87 2013 1 16.943726
     967 213 25121501.836163506   236696 101.20883 2013 2 17.039234
     967 214  27496452.72694253   240656  108.7187 2013 3 17.129568
     967 215 31654405.740024228   239841 125.38672 2013 4 17.270388
     967 216 28668090.011773463   201054 136.14319 2014 1 17.171295
     967 217  28841873.52265626   201735 135.61485 2014 2  17.17734
     967 218 32743869.963989224   197636  156.6265 2014 3 17.304226
     967 219  34136347.46704216   205247  157.1359 2014 4 17.345873
     967 220 30254727.633742694   166223  174.6888 2015 1 17.225163
     967 221  29174848.65959489   156821  177.4915 2015 2 17.188818
     967 222  30737620.45007514   152585  192.7502 2015 3 17.240997
     967 223   30158653.1769133   149513 193.11697 2015 4 17.221983
     968 197  2376854.021345326    69235   33.1783 2009 2  14.68129
     968 198  3890580.543986951   115520  32.08473 2009 3  15.17407
     968 199  5250787.847562533   157870 31.529097 2009 4 15.473888
     968 200  7330260.977733087   211404  33.04153 2010 1 15.807522
     968 201  8450960.750602767   244419 32.825207 2010 2  15.94979
     968 202   9933943.46897207   287766 32.776993 2010 3 16.111467
     968 203 12384495.526179137   358261 33.805927 2010 4 16.331955
     968 204  13200848.13245852   377183  33.89235 2011 1 16.395792
     968 205 14100907.796997774   410218  32.42119 2011 2  16.46175
     968 206  15002854.33816764   456741 30.845716 2011 3  16.52375
     968 207  3699298.846252881   115634  30.78887 2011 4 15.123653
     968 208 233712.83927827814     7215  39.23624 2012 1  12.36185
     968 209  4967673.526070839   150135   30.9579 2012 2 15.418462
     968 210  8852601.338529933   272060 30.249664 2012 3 15.996222
     968 211 12473714.221688677   345016 33.543846 2012 4 16.339134
     968 212 15596767.159814764   431832 33.378513 2013 1 16.562574
     968 213 18959592.999042645   465392  37.69897 2013 2  16.75782
     968 214 22048360.293348596   500569  40.76159 2013 3 16.908749
     968 215 27938974.656602535   546145  46.65392 2013 4 17.145533
     968 216  26750443.86863454   484317  49.64977 2014 1 17.102062
     968 217 26878713.961782422   483588  49.66882 2014 2 17.106846
     968 218 33266045.939542584   514912  61.17122 2014 3 17.320047
     968 219  35334039.34748898   548088  56.82569 2014 4 17.380358
     968 220  31133623.33147834   439270  67.92824 2015 1   17.2538
     968 221 30459023.362540193   423134  63.56718 2015 2 17.231894
     968 222 33996678.285481915   434284  68.73748 2015 3 17.341774
     968 223   34801448.3291206   445275  74.72015 2015 4  17.36517
    4834 186  17311388.39029362 16889139   54.8011 2006 3 16.666876
    4834 187 1388973.0942330845  1288925  55.33047 2006 4 14.144075
    4834 188 1387120.8229355365  1534965  53.47997 2007 1  14.14274
    4834 189 2874908.2771308306  3292322  32.31376 2007 2 14.871531
    4834 190  3757407.736264723  4393833  32.17697 2007 3  15.13924
    4834 191  2843466.347520378  3702495 31.510515 2007 4 14.860535
    4834 192  998555.2974059999  1400908 31.310276 2008 1 13.814065
    4834 193 114041.88963551621   145971   30.9932 2008 2 11.644321
    4834 194 3210.9667879325075     2800  45.42096 2008 3  8.074327
    4834 195  319.2018654527965        2 159.60094 2008 4  5.765824
    4834 196 408.46208155762787      810  .5042742 2009 1  6.012399
    6068 176  140489289.6538338  2426268   30.1741 2004 1 18.760641
    6068 177 141706823.49164075  2321866 32.704742 2004 2  18.76927
    6068 178   139233298.766628  2263469 32.711693 2004 3 18.751661
    6068 179 138094566.12637913  2256874 32.504047 2004 4  18.74345
    6068 180 146198672.40413287  2191173  36.32059 2005 1 18.800476
    6068 181 144707082.56484634  2163173 38.142166 2005 2 18.790222
    6068 182   156916892.148992  2145103   41.4885 2005 3 18.871227
    6068 183 149037388.86023295  2134771  42.89772 2005 4 18.819708
    6068 184  150169842.8261422  2146745  40.87637 2006 1 18.827278
    6068 185 150358546.68755642  2119427  44.96695 2006 2 18.828533
    6068 186  147726275.7866978  2102578  37.85888 2006 3 18.810871
    6068 187 157270542.50865793  2148630  41.68524 2006 4 18.873478
    6068 188  155489053.4775696  2131831  39.23389 2007 1 18.862085
    6068 189 155756948.65891987  2146397  41.88565 2007 2 18.863808
    6068 190 161417564.39199463  2142104  43.45609 2007 3 18.899506
    6068 191  166036535.2769161  2177906  43.81662 2007 4  18.92772
    6068 192 173477518.29809624  2245182  47.75566 2008 1  18.97156
    6068 193 175359045.69731742  2288285  51.28833 2008 2 18.982346
    end
    format %tq trimestre
    What I would like to do is to obtain a deseasonalized version of price and quantity. I have seen that stata provides "tssmooth shwinters " but, as far as I have understood this gives the forecast of seasonalized data. So I don't know if it is useful in order to deseasonalize varibables.

    Thanks,

    Federico

  • #2
    https://www.stata.com/statalist/arch.../msg00100.html
    https://www.stata-journal.com/articl...article=st0255
    Discussions do talk about tssmooth shwinters as useful for deseasonablizing. In essence, a deseasonalized variable is a forecast. But you can try it out and see if it makes sense in a small sample.

    Comment


    • #3
      Example 1 in the PDF documentation for tssmooth shwinters suggests that the forecasts from this command include a forecasted seasonal component, and the documentation further suggests that the forecasted seasonal components could vary over time. One could argue that tssmooth is a misleading command name to include this "smoother", and I wouldn't disagree.

      Comment


      • #4
        William Lisowski Thanks to both of you for the kind reply,

        Discussions do talk about tssmooth shwinters as useful for deseasonablizing. In essence, a deseasonalized variable is a forecast. But you can try it out and see if it makes sense in a small sample.
        Oh yes I saw something about X12 but the problem is that I am running on a Mac and the package seems to be developed for Windows
        @Phil Bromiley

        So I share what I did so that maybe further discussion may be evolve and others could benefit.

        Instead of tssmooth shwinters I went for tssmooth ma after having xtset idprod and trimestre (which is quarter in Italian) as panel identifiers for individual and time.
        My code, hence looks like this:

        Code:
        tssmooth ma sales_adj = salesm, weights( 1 <2> 1)
        tssmooth ma log_sales_adj = log_sales, weights( 1 <2> 1)
        tssmooth ma std_adj = stdunits, weights( 1 <2> 1)
        gen price_adj = sales_adj/std_adj
        Hence my deseasonalised variables are respectively: sales_adj, std_adj, price_adj.

        Do you think this method works fine? I read that tssmooth ma works fine for panel data once idpr and time variables are set.

        Thank you!

        Last edited by Federico Nutarelli; 04 Dec 2019, 10:56.

        Comment

        Working...
        X