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

st: Re: programming graphical report

From   "Steve" <>
To   <>
Subject   st: Re: programming graphical report
Date   Thu, 13 Nov 2008 07:19:16 -0600

Friedrich Huebler responded with example code (see below) to my request to produce and store a long series of graphs for import into another package for a report. After some playing with the code to meet my specific requirements, the code does exactly what I needed.

Thanks to Friedrich for his expert help.

Steve Rothenberg


Here is an example to get you started. It shows how to loop over
departments and individuals and how to name the graphs. The first four
lines set up the data. The part you are interested in starts with

sysuse auto, clear
bysort foreign: keep if _n<3
rename make name
decode foreign, gen(dept)
levelsof dept, local(depts)
levelsof name, local(names)
foreach d of local depts {
 foreach n of local names {
   capture graph bar mpg ///
     if dept=="`d'" & name=="`n'", ///
     title("`d', `n'")
   if _rc==0 {
     graph export "`d', `n'.emf"


----- Original Message ----- From: "Steve" <>
To: <>
Sent: Friday, November 07, 2008 6:26 PM
Subject: programming graphical report


I've been asked to produce a report of an evaluation of an institution divided into some 20 separate departments each with approximately 30 individuals (variable number in each department). The data are arranged wide, with a string ID variable (individual name), a string department variable, and three numeric variables for the evaluation scales.

The report will be strictly graphical and its purpose is to place each individual on a cumulative summary of each department's ratings on three scales. Thus I calculate the cumulative proportions of each scale for each department by

. by dept, sort : cumul desemp, generate(desacum) equal

. by dept, sort : cumul cond, generate(condacum) equal


I've manually generated the basic graph example with:

. twoway line desac desemp if dept=="1A", sort || scatter desacum desemp in 4, msize(large)

This gives me a line plot with proportion of responses in the department on the y-axis and the ratings for a scale on the x-axis with the line showing the cumulative plot (first part of command); it also gives me an individual's scale score (from the fourth line of the data set), plotted as a large dot on the line (second part).

The present graph code uses a hardcoded -if- statement to restrict the plotting of the cumulative response to one department and a hard-coded -in- statement to pull the individual's score on that rating scale and plot it on the cumulative line for his department drawn by the first part of the command.

I want to go on to the second and third rating scales for that department and individual and use -graph combine- to produce a matrix of the cumulative ratings for that department and individual in the format:


and do the same for each individual in that department, each time producing the graphical matrix for each individual. Then (or right after each -graph combine-), store the graphical matrix in an enhanced window metafile for import into a Word page, with the name of the .emf file a composite of the two letter department name and the first 10 letters of the subject ID (with spaces) for that matrix.

With over 600 individuals, it's clear it should not be done by hand.

After exhausting the individuals in the first department, the program should move on to the next departments and groups of individuals, producing a one page graphic matrix for each individual.

I've read sections of the User and Programming manuals on loops and macros, but can't figure out how to do the double indexing that's needed, nor to assign file names of output using parts of the two string variables for ID and department.

I'm using a Vista Windows machine, Stata MP 10.1, 2 GBytes memory.

Steve Rothenberg

*   For searches and help try:

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