Announcement

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

  • How to run this formula on stata = [Standard Deviation * (trading days) 1/2 ] , for a number of series.

    Hello,
    In the attached data below, in the first column there is 1, 1, 1…. 1 which means first security, then 2, 2, 2…..2 mean second security and so on till 501 which means 501th security. Each number is 19 times in the month of July, which shows that particular security is traded for 19 days except a few securities . Second column is the residuals series of 501 securities in the month of July, 2005. I got these residuals after employing OLS on daily data for each security with the help of Stata.
    Similarly, I have got these residuals series of 501 securities for each month from the period of July 2005 to June 2019. Below I am just showing a sample of my data set.
    Now I want to calculate = [Standard Deviation * (trading days) 1/2 ] for each security every month. In MS Excel I have to calculate for each security which is very time consuming.

    I run this command:
    Code:
    dataex Securities Residuals
    My data is look like:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int Securities double Residuals
    1    .06100905526664617
    1   .018200765921769196
    1   .002302944490864386
    1  -.033965307491921164
    1  .0009181674237631124
    1    .06403532828369113
    1    .05333690686003768
    1   .015190512297211294
    1   .005032692203814661
    1   -.03426425281175801
    1  -.002881117047946408
    1   -.03371983377341705
    1  -.038556254176230764
    1  -.011430591851673392
    1  -.019482834034763565
    1   -.03404594016616286
    1   -.05031003388061296
    1   .014875586087672074
    1   .023754206399016434
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    2                     .
    3  -.004844024826951678
    3  -.018068070155601464
    3    .06367076469697697
    3    .03809349127519174
    3  -.004253538158807668
    3 -.0028536664163587733
    3  .0046647922571916856
    3  -.017304186793684666
    3  -.015854318387752496
    3  -.004021355277043498
    3   .013462510497008263
    3  -.007330210581243784
    3  -.013201097967129819
    3 -.0034195904319810643
    3   -.01583547289747817
    3   -.01513205173650813
    3    .01646283312031617
    3   .001470463671279395
    3  -.015707271887423033
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    4                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    5                     .
    6    .00398852613465446
    6  -.007123296989719599
    6  -.006353320411417913
    6  -.006491804673747924
    6   .004909149193909702
    end
    dataex command is not showing the complete series as this has 9,519 observations. Sir please suggest some possible ways of doing this on Stata so that it save my time.
    Thank you
    PRIYA

  • #2
    For the given data, this should do
    Code:
    bys Securities : egen sd = sd(Residuals )
    bys Securities : egen n = count(Residuals )
    gen wanted = sd * sqrt(n)
    list in 1/10
    
         +--------------------------------------------------+
         | Securi~s    Residuals         sd    n     wanted |
         |--------------------------------------------------|
      1. |        1    .06100906   .0343241   19   .1496152 |
      2. |        1    .01820077   .0343241   19   .1496152 |
      3. |        1    .00230294   .0343241   19   .1496152 |
      4. |        1   -.03396531   .0343241   19   .1496152 |
      5. |        1    .00091817   .0343241   19   .1496152 |
         |--------------------------------------------------|
      6. |        1    .06403533   .0343241   19   .1496152 |
      7. |        1    .05333691   .0343241   19   .1496152 |
      8. |        1    .01519051   .0343241   19   .1496152 |
      9. |        1    .00503269   .0343241   19   .1496152 |
     10. |        1   -.03426425   .0343241   19   .1496152 |
         +--------------------------------------------------+
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment


    • #3
      Thank you so much @Shah sir for your valuable reply.

      Comment

      Working...
      X