Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: xline macro or scalars

From   "Nick Cox" <>
To   <>
Subject   RE: st: RE: xline macro or scalars
Date   Wed, 24 Sep 2003 17:15:36 +0100

Buzz Burhans
> You correctly interpreted my attempted task, and I will 
> tuck your solution 
> away for another similar situation.  I have a couple of 
> questions about 
> your solution.  What I needed was a way to mark (by an xline) the 
> occurrence of, variably, one, two, or three events on the x 
> axis of an 
> xtline graph.  It looks like the line I reproduce below 
> would give me only 
> a single xline per xtline graph, is that correct? 

No. You should get up to 3 lines, by virtue of the 
-forvalues- loop. Here's the code again: 

levels id, local(levels)
foreach l of local levels {
         // next line clears macro
         local events
         forval i = 1/3 {
                 su event`i' if id == `l', meanonly
                 if r(max) < . local events "`events'`r(max)' "
         if "`events'" != "" {
                 xtline response if id == `l', ///
                 subtitle(panel `l') xline(`events')
         else xtline response if id == `l', subtitle(panel `l')

The -forvalues- loop loops over -event1- to -event3-. 
Of course, your variable names may well be something else, 
and may not have such structure. 

Let's say -engaged-, -married-, -firstchild-, although 
as I recall you deal with cows, so the events might 
differ. Anyone, let's stick with that case, which 
you can handle this way: 

local events 
foreach v of var engaged married firstchild { 
	su `v' if id == `l', meanonly 
	if r(max) < . local events "`events'`r(max)' "

I didn't get as far as thinking 
about how you would distinguish the lines on 
the graph. 

> And would you then 
> continue the three options as overlayed graphs to create a 
> singel graph with the three possible lines?
> the line that looks like it grabs a single event to me is:
> >                 if r(max) < . local events "`events'`r(max)' "

No. As said, it's in a loop. 

> Second question, not at all a priority.  Is there a way to 
> use mkmat to 
> accomplish this? That was where I was headng when I 
> realized I could use 
> recast(rcap) to create capped lines at each event 
> occurrence and mark them 
> that way.

Sorry, I have no idea how -mkmat- would connect to this. 
I think you need to spell out why and how you think 
it is needed. 

*   For searches and help try:

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