Announcement

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

  • How to generate this formula

    Hello, I need help from every expert, I want to generate this formula. How to use "rangestat" to make it or other ways.
    Click image for larger version

Name:	1.jpg
Views:	1
Size:	19.5 KB
ID:	1667052

    (sorry, the word is a little tie, so I expand the fig)
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float t double sum_sentiment
     1  .0288127515759094
     2 -.0904761904761904
     3   .113189484126984
     4   .143840852130325
     5   .214285714285714
     6  .0275213675213675
     7  -.333333333333333
     8  .0197083794758213
     9  .0621107331821617
    10  .0865143862871135
    11  .0175470219435736
    12   .115094302398989
    13  .0286485545106234
    14  .0687808172914556
    15  .0211010709504685
    16   .109090909090909
    17   .119491470830756
    18                -.2
    19   .133333333333333
    20                -.1
    end

  • #2
    Isn't this just exponential smoothing as implemented by tssmooth?

    Still, this is an attempt using rangerun from SSC. You may wish to discard results based on incomplete windows.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float t double sum_sentiment
     1  .0288127515759094
     2 -.0904761904761904
     3   .113189484126984
     4   .143840852130325
     5   .214285714285714
     6  .0275213675213675
     7  -.333333333333333
     8  .0197083794758213
     9  .0621107331821617
    10  .0865143862871135
    11  .0175470219435736
    12   .115094302398989
    13  .0286485545106234
    14  .0687808172914556
    15  .0211010709504685
    16   .109090909090909
    17   .119491470830756
    18                -.2
    19   .133333333333333
    20                -.1
    end
    
    capture program drop myprog 
    
    program myprog 
        gen double wtsum = sum_sentiment[_N]
        gen count = _N 
        local I = _N - 1 
        forval i = 1/`I' { 
            replace wtsum = wtsum + sum_sentiment[_N - `i'] * exp(`i'/7)
        } 
    end 
    
    rangerun myprog    , use(sum_sentiment) interval(t -6 0)
    
    list
    
         +--------------------------------------+
         |  t   sum_sent~t        wtsum   count |
         |--------------------------------------|
      1. |  1    .02881275    .02881275       1 |
      2. |  2   -.09047619   -.05723881       2 |
      3. |  3    .11318948     .0471608       3 |
      4. |  4    .14384085     .1982439       4 |
      5. |  5    .21428571    .44297294       5 |
         |--------------------------------------|
      6. |  6    .02752137    .53851944       6 |
      7. |  7   -.33333333    .28788384       7 |
      8. |  8    .01970838    .27347992       7 |
      9. |  9    .06211073    .62352738       7 |
     10. | 10    .08651439    .49811283       7 |
         |--------------------------------------|
     11. | 11    .01754702    .20115257       7 |
     12. | 12     .1150943    -.2353521       7 |
     13. | 13    .02864855   -.31765622       7 |
     14. | 14    .06878082    .60843767       7 |
     15. | 15    .02110107    .66940054       7 |
         |--------------------------------------|
     16. | 16    .10909091    .71245346       7 |
     17. | 17    .11949147    .70618235       7 |
     18. | 18          -.2    .56692949       7 |
     19. | 19    .13333333     .4744646       7 |
     20. | 20          -.1    .36945091       7 |
         +--------------------------------------+

    Comment


    • #3
      thank you professor

      Comment


      • #4
        Hello professor
        May I inquire some questions? Your code is wonderful.
        However, I want to learn what's means.

        First, "gen double wtsum = sum_sentiment[_N]" , it would run a zero vector, why?

        Second, local I = _N - 1
        forval i = 1/`I' {
        replace wtsum = wtsum + sum_sentiment[_N - `i'] * exp(`i'/7)
        }

        end
        it would run a 1.7322000e+101 of vector, why?

        Comment


        • #5
          Sorry I don't understand what you're asking in #4 at all.

          Comment


          • #6
            I am sorry, I forgot the dataset is different
            OK repeat one again


            First, "gen double wtsum = sum_sentiment[_N]" , it would run a -.1 vector, why?

            Second, local I = _N - 1
            forval i = 1/`I' {
            replace wtsum = wtsum + sum_sentiment[_N - `i'] * exp(`i'/7)
            }

            end
            it would run a 3.485122131255 of vector, why?

            Comment


            • #7
              Sorry, I fail again to follow what you are asking.

              Comment


              • #8
                Why the ""gen double wtsum = sum_sentiment[_N]" can generate a vector about -.1?


                Click image for larger version

Name:	1.jpg
Views:	1
Size:	92.0 KB
ID:	1667193

                Comment


                • #9
                  If you use that command outside of rangerun it records the last value in the dataset.

                  When rangerun issues that command within a program it applies only to the window of observations being analysed at any one point.

                  Comment

                  Working...
                  X