Announcement

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

  • How to generate the mean value of a time series variable over a period?

    Dear all.

    I want to generate the mean value of a time series variable over a period.

    My sample code is as below.

    Code:
    egen var1 = mean(var) if  yq >= 1979 & yq <= 2016
    But I want to attain a single value of its mean instead of a series.

    Thanks for any help.



  • #2
    Code:
    summ var if inrange(yq, 1979, 2016), meanonly
    local result = r(mean)
    
    display `result'

    Comment


    • #3
      Thanks for Clyde's help. But how to use `result' if I want to derive an formula as below.
      Code:
      gen alpha1rho = (1-Lrate)*result
      Thanks.

      Comment


      • #4
        Clyde has already signalled that. Use local macro punctuation. See [U] 18 for more.

        Alternatively use a scalar:

        Code:
        summ var if inrange(yq, 1979, 2016), meanonly  
        scalar result = r(mean)  
        gen alpha1rho = (1-Lrate)*result

        Comment


        • #5
          Hi Prof. Nick. Thanks for your help.

          Comment

          Working...
          X