Announcement

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

  • Multiply and add

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(time accp delta_accp)
     1 37.97         .
     2 38.07 1.0026336
     3 38.06  .9997374
     4 38.09 1.0007882
     5 38.13 1.0010501
     6 38.18 1.0013113
     7 38.15  .9992143
     8 38.11  .9989515
     9 38.01   .997376
    10 38.05 1.0010524
    11 38.13 1.0021025
    12 38.11  .9994755
    13 38.09  .9994752
    14 38.12 1.0007876
    15 38.11  .9997377
    16 38.14 1.0007871
    17 38.23 1.0023597
    18 38.32 1.0023541
    19 38.32         1
    20 38.36 1.0010439
    end
    Dears, suppose i have an stock accp and it's variation delta_accp (accp/L.accp) as shown above.
    I would like to invest $1000 and have the table bellow:
    time accp delta_accp
    1 37.97 1000
    2 38.07 1.0026 1002.634
    3 38.06 0.9997 1002.37
    4 38.09 1.0008 1003.16
    5 38.13 1.0011 1004.214
    6 38.18 1.0013 1005.531
    7 38.15 0.9992 1004.741
    8 38.11 0.9990 1003.687
    9 38.01 0.9974 1001.053
    10 38.05 1.0011 1002.107
    11 38.13 1.0021 1004.214
    12 38.11 0.9995 1003.687
    13 38.09 0.9995 1003.16
    14 38.12 1.0008 1003.95
    15 38.11 0.9997 1003.687
    16 38.14 1.0008 1004.477
    17 38.23 1.0024 1006.848
    18 38.32 1.0024 1009.218
    19 38.32 1.0000 1009.218
    20 38.36 1.0010 1010.271
    What Stata code must i use?

    Thanks

    Eli Hadad Junior




  • #2
    Code:
    gen value = 1000 in 1
    replace value = value[_n-1]*delta_accp if _n > 1
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you Maarten !

      Comment

      Working...
      X