Announcement

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

  • Doubt with x-axis of an incomplete time series

    Some time ago Nick Cox helped me with an example of a time series so I had a better view. So far I have worked with complete series but the question arose, can you make a graph with a series that is not complete? that is, for example, start in the third quarter of 1967 but respecting the idea of Nick Cox. I have tried to adjust it but the divisions move which does not allow me to get the result.

    I attach the code in case someone can give me some suggestions.

    Greetings

    Code:
    clear
    
    input int date float gnp96
    28 3631.6
    29 3644.5
    30   3672
    31 3703.1
    32 3757.5
    33 3818.3
    34 3841.6
    35 3861.8
    36 3906.8
    37   3915
    38 3937.8
    39 3922.9
    40   3922
    41 3922.3
    42 3961.3
    43   3931
    44 4027.3
    45   4042
    46 4064.7
    47 4072.9
    end
    
    format %tqq date
    set scheme s1color 
    
    
    #delimit ;
    
    twoway connected gnp96 date, 
    
    xmla(28/47, tlength(0)) 
    xtick(27.5(4)47.5, tlength(*5)) 
    xla(29.5(4)45.5, format(%tqCCYY) tlength(*2) tlcolor(none))
    
    title("")
    
    ;
    
    #delimit cr

  • #2
    I've achieved what I wanted, it's very manual, but I suppose it can be automated if the series is longer. For now, I leave you with the example.

    Thank you very much, and I appreciate any feedback for improvement.

    Best regards.


    Code:
    clear
    
    input int date float gnp96
    28 3631.6
    29 3644.5
    30 3672
    31 3703.1
    32 3757.5
    33 3818.3
    34 3841.6
    35 3861.8
    36 3906.8
    37 3915
    38 3937.8
    39 3922.9
    40 3922
    41 3922.3
    42 3961.3
    43 3931
    44 4027.3
    45 4042
    46 4064.7
    47 4072.9
    end
    
    format %tqq date
    set scheme s1color
    
    #delimit ;
    
    twoway connected gnp96 date if date >= 30, /// // Comenzamos en el tercer trimestre de 1967
    xmla(30/47, tlength(0))
    xtick(29.5 31.5(4)47.5, tlength(*5)) /// Ticks en intervalos anuales, respetando la estructura original
    xla( 30.5 33.5(4)45.5, format(%tqCCYY) tlength(*2) tlcolor(none))
    
    title("")
    
    ;
    
    #delimit cr
    Last edited by Juan Carlos; 20 Oct 2024, 19:30.

    Comment


    • #3
      The extra code reproduces your graph.


      Code:
      clear
      
      input int date float gnp96
      28 3631.6
      29 3644.5
      30 3672
      31 3703.1
      32 3757.5
      33 3818.3
      34 3841.6
      35 3861.8
      36 3906.8
      37 3915
      38 3937.8
      39 3922.9
      40 3922
      41 3922.3
      42 3961.3
      43 3931
      44 4027.3
      45 4042
      46 4064.7
      47 4072.9
      end
      
      format %tqq date
      set scheme s1color
      
      #delimit ;
      
      twoway connected gnp96 date if date >= 30, /// // Comenzamos en el tercer trimestre de 1967
      xmla(30/47, tlength(0))
      xtick(29.5 31.5(4)47.5, tlength(*5)) /// Ticks en intervalos anuales, respetando la estructura original
      xla( 30.5 33.5(4)45.5, format(%tqCCYY) tlength(*2) tlcolor(none)) name(G1, replace)
      
      title("")
      
      ;
      
      #delimit cr
      
      * extra code starts here 
      
      
      local select if date >= 30 
      
      summarize date `select', meanonly 
      local min = r(min)
      local max = r(max)
      
      gen year = year(dofq(date)) 
      
      egen where1 = mean(date) `select', by(year)
      
      levelsof where1, local(labels) 
      
      gen quarter = quarter(dofq(date)) 
      
      gen where2 = date - 0.5 `select' & (quarter == 1 | date == `min')  
      
      replace where2 = date + 0.5 if date == `max' 
      
      levelsof where2, local(ticks) 
      
      twoway connected gnp96 date `select',  xmla(`min'/`max', tlength(0)) ///
      xtick(`ticks', tlength(*5)) xla(`labels', format(%tqCCYY) tlength(*2) tlcolor(none)) name(G2, replace)
      Click image for larger version

Name:	qdate.png
Views:	1
Size:	45.8 KB
ID:	1766153

      Comment


      • #4
        Thank you @Nick Cox, as always it is a pleasure to read your answers.

        Greetings

        Comment


        • #5
          I think Juan Carlos was alluding in #1 to the thread https://www.statalist.org/forums/for...is-double-time where some references may also be found with more explanation.

          Comment

          Working...
          X