Statalist


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

st: Re: programming graphical report


From   "Steve" <drlead@prodigy.net.mx>
To   <statalist@hsphsun2.harvard.edu>
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
CINVESTAV
Mexico

Steve,

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
-levelsof-.

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"
   }
 }
}

Friedrich


----- Original Message ----- From: "Steve" <drlead@prodigy.net.mx>
To: <statalist@hsphsun2.harvard.edu>
Sent: Friday, November 07, 2008 6:26 PM
Subject: programming graphical report


Listers:

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

etc.

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:

X X
   X

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
CINVESTAV
Mexico

*
*   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   |   What's new   |   Site index