Announcement

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

  • pergram (periodogram)

    I started to use pergram, which is very useful.
    However, I would like to change the X axis to the cycle (instead of the Frequency). Can I?

    I used to use R to make a periodgram. With R, you can output the relationship between Frequency and Intensity, from which you can make an alternative graph with X axis of cycle (=1/F).

  • #2
    It's a little convoluted, because the documentation doesn't really describe what -pergram- leaves behind, but the do-file posted below shows how to do it. It uses one of the example datasets that are used in the help file for -pergram- and in Example 4 of the user's manual entry for the command.
    Code:
    version 17.0
    
    clear *
    
    quietly webuse cos4
    pergram sumfc, generate(ordinate) nograph
    
    quietly summarize sumfc
    tempname den
    scalar define `den' = r(Var) * (r(N) - 1)
    generate double amp = ln(ordinate / `den')
    quietly replace amp = cond(amp < -6, -6, cond(6 < amp, 6, amp))
    label variable amp Amplitude
    
    generate double omega = (_n - 1) / _N
    label variable omega Frequency
    
    pause on
    graph twoway line amp omega if omega <= 0.5, sort ///
        lcolor(black) ylabel( , angle(horizontal) nogrid)
    // quietly graph export freq.png
    pause
    
    quietly generate double cycle = 1 / omega
    label variable cycle Period
    
    graph twoway line amp cycle if omega <= 0.5, sort ///
        lcolor(black) xscale(log) xlabel(3 6 12 36) ///
            ylabel( , angle(horizontal) nogrid)
    // quietly graph export peri.png
    
    exit

    Comment


    • #3
      Joseph, thank you!!

      Comment

      Working...
      X