Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Graphing monthly (time series) data in STATA 11


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Graphing monthly (time series) data in STATA 11
Date   Mon, 3 May 2010 18:54:09 +0100

In addition to other answers: 

I was going to suggest that you would be better off treating the data as the monthly time series that they are, but that makes some things more difficult and some things easier. 

Some extra technique: 

gen monthlabel = substr("JFMAMJJASOND", month(date2), 1)
labmask numdate, values(monthlabel)
levelsof numdate, local(levels)
line ricepr numdate, xla(`levels', valuelabel)

For -labmask-, -findit labmask- for sources. 

Nick 
n.j.cox@durham.ac.uk 

Broca, Sumiter (FAORAP)

  I have the following MONTHLY data on wholesale rice prices (Riel / kg.) in
Phnom-Penh, in the format in which they were downloaded (as a CSV file) from
http://www.fao.org/giews/pricetool/ . 
 
date               ricepr
01/01/2006   700
01/02/2006   700
01/03/2006   900
01/04/2006   900
01/05/2006   900
01/06/2006   900
01/07/2006   900
01/08/2006   933.33
01/09/2006   1000
01/10/2006   1000
01/11/2006   1000
01/12/2006   1000
01/01/2007   1050
01/02/2007   1087.5
01/03/2007   1100
01/04/2007   1100
01/05/2007   1100
01/06/2007   1100
01/07/2007   1175
01/08/2007   1200
01/09/2007   1200
01/10/2007   1300
01/11/2007   1400
01/12/2007   1400

 
1. I read the data into STATA 11 and then changed the "Date" variable into a
time variable with the command:
             gen date2 = date(date, "DMY"). 
 
2. I formatted date2 with the following command: 
             format date2 %td
 
2. de gives the following output: 
Contains data
  obs:            24                          
 vars:             3                          
 size:           528 (99.9% of memory free)
-----------------------------------------------------------------------------
----------------------------
              storage  display     value
variable name   type   format      label      variable label
-----------------------------------------------------------------------------
----------------------------
date            str10  %10s                   Date
ricepr          float  %8.0g                  Cambodia, Phnom Penh, Rice
(Mix), Wholesale, Riel, Kg
date2           float  %td                    
-----------------------------------------------------------------------------
----------------------------
Sorted by:  
     Note:  dataset has changed since last saved

 
3. Then I tried to graph the data with the following command:
   line ricepr date2. 
 
 
4. When the graph appeared in the graph window, it had the following (ugly)
labels on the x-axis: 
 
01jan2006-------01apr2006---------01jul2006--------01oct2006-----------01jan2
007
 
 
5. Ideally I would like to get a nice set of x-axis labels that look like
this:
 
J--F--M--A--M--J--J--A--S--O--N--D--J--F--M--A--M--J--J--A--S--O--N--D
                            2006
2007
 
 
5. Or the following, where each tick (|) represents a month, but is not
labelled with the month name: 
 
   |      |      |      |      |      |      |      |      |      |      |
|      |      |      |      |      |      |      |      |      |      |
|      |      | 
-----------------------------------------------------------------------------
----------------------------------
2006
2007
2008
 

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index