Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Computing standard deviations


From   "de la Garza, Adrian" <[email protected]>
To   <[email protected]>
Subject   st: Computing standard deviations
Date   Fri, 23 Jan 2004 16:31:50 -0500

Anyone has an idea on how to do the following...? 

I have a dataset in panel format country-time, where time is given in
monthly frequency. I need to take standard deviations of six-month
periods within a same variable and then put the results in the following
quarter. This is what I have:

          country   year   month   quar       xgrth
        Argentina   1990       1      1     .104022  
        Argentina   1990       2      1    .1645495  
        Argentina   1990       3      1    .5374349  
        Argentina   1990       4      2    .3808163  
        Argentina   1990       5      2    .2779705  
        Argentina   1990       6      2    .1380076  
        Argentina   1990       7      3    .2144917  
        Argentina   1990       8      3    .2108712  
        Argentina   1990       9      3    .2187464  
        Argentina   1990      10      4    .3077441  
        Argentina   1990      11      4    .3684135  
        Argentina   1990      12      4    .6138677  
       Bangladesh   1990       1      1    .3315367  
       Bangladesh   1990       2      1    .3801939  
       Bangladesh   1990       3      1    .2396672  
       Bangladesh   1990       4      2    .0442909  
       Bangladesh   1990       5      2    .3605669  
       Bangladesh   1990       6      2    .3493509  
       Bangladesh   1990       7      3    .5702868  
       Bangladesh   1990       8      3    .2717893  
       Bangladesh   1990       9      3    .3432341  
       Bangladesh   1990      10      4    .2450083  
       Bangladesh   1990      11      4    .1813706  
       Bangladesh   1990      12      4    .1414036  

And what I need is to take the standard deviation by country and for
every two consecutive quarters and store that number in the following
quarter. So, eventually, I will convert the dataset given in monthly
frequency (as shown) to quarterly frequency. I was thinking of taking,
by country and for every row, the standard dev of the previous six
observations, and then lag everything by three months and then collapse
everything into quarters. But I don't know how to take the std devs... 

Something like this is what I could do, except that I know the -in- part
is not syntactically correct:

by country: egen stdev = sd(xgrth) in xgrth[_n-5]/xgrth

any ideas?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index