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

RE: st: help with a histogram by year

From   "Nick Cox" <>
To   <>
Subject   RE: st: help with a histogram by year
Date   Tue, 10 Mar 2009 15:24:36 -0000

My advice to Faye is that titles like "1990", "1991" are fine. 

Adding "For year" repeatedly just adds busy detail without adding

But, that aside, in terms of how you would best do it in Stata, I agree
with Richard. 

The key is that the -by:- part looks at the value labels if they exist
and the values if they don't. So, arrange some suitable labels in
advance. (This is cleaner than using -graph combine-.) 

Here is a systematic way to do it. 

1. Leave the -by()- variable exactly as is, but clone it: 

clonevar year2 = year 

2. Define the labels: 

levelsof year2, local(years) 
foreach y of local years { 
	label define year2 `y' "for year `y'", add 
label val year2 year2 

3. Now do your graph using -by(year2)-. 


Richard Ochmann

alternatively to Martin's approach you could write your titles of the 
subgraphs in the value labels of the by-variable:

sysuse auto, clear
gen year = cond(runiform()<0.3,1978, cond(runiform()<0.6,1979,1980))
label define yearlab 1978 "For year 1978" 1979 "For year 1979" 1980 "For

year 1980", modify
label values year yearlab
histogram price, by(year, note(""))

"F. Gao" <> 

I am trying to get a histogram by year. I use the following command

hist y, by(year,graphregion(color(white))) freq

2. I would like to add a small title under each graph for each year,
such as "For year 1990", "For year 1991", so that I could replace the
title added by stata automatically on the top of each graph, like
"1990", "1991".

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index