Announcement

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

  • Can Stata draw curved line, even manually ?

    Dear all
    Is there a way to draw a curved line in a graph in Stata, even manually ?
    I want to draw a business cycle similar to the one in the attached graph. My aim is to draw the typical business cycle in a graph and then incorporate my actual data (that i have found to mimic the business cycle turning points)...The problem now is with drawing this business cycle.

    I tried to draw a grpah in stata and then draw a curved line similar to the business cycle after opening the graph editor. Unfortunately, I found only straight lines available to be incorporated into the graph.

    Thanks for your help
    Lisa
    Attached Files

  • #2
    Like this?

    Code:
    clear
    set obs 1000
    gen x = _n
    gen y = 100*sin(x/100) + .25*x + 100
    line y x

    Comment


    • #3
      Another option would be to smooth the data or even fit a curve to it:

      Code:
      webuse sales1, clear
      tssmooth ma sm1=sales, window(2 1 2 )
      tw (connected sales t) (line sm1 t) (lpoly sales t)

      Comment


      • #4
        Here is a cool way to graph any separable function, y=f(x). The example below approximates the curve specified in your drawing, but you can edit what comes after function to be anything. It also uses twoway as suggested by Dimitriy.

        Code:
        graph twoway (function y=sin(3*x*3.14159)+x)

        Comment


        • #5
          Dear all
          Thanks a lot for your suggestions.I find the one in #4 by Leonardo helpful and generic.

          The problem now is that I want this curve to be incorporated in the graph I have attached in this current post, where the peak in the curve (in #1) parallels the event year in my new graph (in post #5). Also, another graph where the trough parallels the event year.

          Any help is much appreciated.
          Thanks you so much.
          Lisa
          Attached Files
          Last edited by Lisa Wilson; 21 Aug 2016, 20:47.

          Comment


          • #6
            Dear all
            To clarify I use this code to produce the graph in #5
            Code:
            gen peak1=0
            replace peak1=1 if year==1973&qtr==4
            
            gen peak2=0
            replace peak2=1 if year==1980&qtr==1
            
            gen peak3=0
            replace peak3=1 if year==1981&qtr==3
            
            gen peak4=0
            replace peak4=1 if year==1990&qtr==3
            
            gen peak5=0
            replace peak5=1 if year==2001&qtr==1
            
            gen peak6=0
            replace peak6=1 if year==2007&qtr==4
            
            
            egen eventyr1=max(cond(peak1==1, fqdate, .))
            gen timesinceevent1= fqdate-eventyr1
            
            egen eventyr2=max(cond(peak2==1, fqdate, .))
            gen timesinceevent2= fqdate-eventyr2
            
            egen eventyr3=max(cond(peak3==1, fqdate, .))
            gen timesinceevent3= fqdate-eventyr3
            
            egen eventyr4=max(cond(peak4==1, fqdate, .))
            gen timesinceevent4= fqdate-eventyr4
            
            egen eventyr5=max(cond(peak5==1, fqdate, .))
            gen timesinceevent5= fqdate-eventyr5
            
            egen eventyr6=max(cond(peak6==1, fqdate, .))
            gen timesinceevent6= fqdate-eventyr6
            
            twoway (scatter shock timesinceevent1 if inrange(timesinceevent1, -4, 4), connect(l) sort) ///
            (scatter shock timesinceevent2 if inrange(timesinceevent2, -4, 4), connect(l) sort) ///
            (scatter shock timesinceevent3 if inrange(timesinceevent3, -4, 4), connect(l) sort) ///
            (scatter shock timesinceevent4 if inrange(timesinceevent4, -4, 4), connect(l) sort) ///
            (scatter shock timesinceevent5 if inrange(timesinceevent5, -4, 4), connect(l) sort) ///
            (scatter shock timesinceevent6 if inrange(timesinceevent6, -4, 4), connect(l) sort)
            Does anyone know how to draw incorporate a curve similar to #1 where the peak parallels the event year?

            Thank you

            Comment


            • #7
              Dear all
              This is quite old now.
              Any suggestion here?

              The code used in #6 shows the behavior of the variable "shock" four quarters before and after peak1, peak2...peak6.
              All what I need is to incorporate the actual cycle as in #1 ??

              Comment

              Working...
              X