0
votes

I have produced a graph using the community-contributed command tableplot.

The graph itself is fine, but on the x-axis there are a lot of years, which overlap and are not legible. I have thus tried to label only every decade or something similar. My initial attempts did not work, so I checked the Stata manual.

However, the manual appears to confirm that I coded it correctly xlabel(1935(5)1955). I then tried to feed Stata a fixed number of labels xlabel(#10). This works better, but the first label is year 0. Obviously year 0 is not in the data and there are no missing values or any other issues with the data.

I have reproduced the problem with an example dataset below and the problems are the same:

use http://www.stata-press.com/data/r15/grunfeld.dta, clear
codebook year

tableplot rbar invest company year, graphregion(color(none)) bgcolor(white) subtitle("") ///
xtitle("Year") ytitle("Firm")

tableplot rbar invest company year, graphregion(color(none)) bgcolor(white) subtitle("") ///
xtitle("Year") ytitle("Firm") xlabel(1935(5)1955)

*Coding is in line with Stata manual page 9: 
*https://www.stata.com/manuals13/g-3axis_label_options.pdf

tableplot rbar invest company year, graphregion(color(none)) bgcolor(white) subtitle("") ///
xtitle("Year") ytitle("Firm") xlabel(#10)

I would be happy if somebody could point out to me how I can convince Stata and tableplot to label the x-axis from a specified start-year(1935) to an end-year(1955) with a given interval in between.

I use Stata 15 and the most up to date version of tableplot.

2
Thanks! That is indeed the solution: tableplot rbar invest company year, graphregion(color(none)) bgcolor(white) subtitle("") xtitle("Year") ytitle("Firm") xlabel(1(5)20) I do not understand why it is setup in this way, but thanks! - Christoph

2 Answers

2
votes

You are not graphing year but time:

tableplot rbar invest company year, graphregion(color(none)) bgcolor(white) ///
subtitle("") xtitle("Year") ytitle("Firm") xlabel(1(19)20)

enter image description here

So the best result given your data is the following:

tableplot rbar invest company year, graphregion(color(none)) bgcolor(white) ///
subtitle("") xtitle("Year") ytitle("Firm") xlabel(1(6)20)

enter image description here

You may be able to get better results by further fiddling with the different options.


EDIT:

Apparently I had forgotten that the xasis option can also be used:

tableplot rbar invest company year, graphregion(color(none)) bgcolor(white) ///
subtitle("") xtitle("Year") ytitle("Firm") xlabel(1935(5)1955) xasis

enter image description here

1
votes

tableplot (SSC) was last revised in 2009. I would recommend instead using tabplot (Stata Journal), which is being maintained.

webuse grunfeld

tabplot company year [iw=invest], graphregion(color(none))  bgcolor(white) /// 
subtitle("") xtitle("Year") ytitle("Firm") xasis xla(, format(%tyY))

tabplot company year [iw=invest], graphregion(color(none))  bgcolor(white)  /// 
subtitle("") xtitle("Year") ytitle("Firm") xasis xla(1935(5)1955)

The main twist behind tabplot (and of tableplot too) is the use of table-like data, with the implications that you want to know which row and which column are which. But in this example with a period of 20 years you could show in the axis labels just the last 2 digits or some years only.