Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: accessing value labels into a loop


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: accessing value labels into a loop
Date   Mon, 21 May 2012 20:35:27 +0100

There is quite a lot you don't explain, but the main advice is to look
at -help extended fcn- to see how to look up value labels if you know
the values.

forval i = 1/3 {
       forval j = 1/3 {
              su x1 if var==`i'`j', meanonly
              local one `r(min)'
              su x2 if var==`i'`j', meanonly
              local two `r(min)'

              graph {variables} if var==`i'`j', by(variable) ///
              title(`: label (x1) `one'') xtitle(`: label (x2) `two'')
      }
}

On Mon, May 21, 2012 at 7:44 PM, ricardo mora <[email protected]> wrote:
> Hello, I am trying to run a program in which I have to use each specific
> label of a pair of variables, and all its combinations together.
> Lets say I have variables x1 and x2:
> x1 value labels are
> 1 A
> 2 B
> 3 C
> and x2 value labels are
> 1 X
> 2 Y
> 3 Z
>
> In an loop I create graphs that should contain both labels combined. This is
> the loop that creates de 9 graphs I need:
>
> foreach r of numlist 11 12 13 21 22 23 31 32 33 {
> local z1 = int(r/10)
> local z2 = 10*((r/10)-int(r/10))
> graph {variables} if var==`r', by(variable) title(label for x1:"A, B or C")
> xtitle(label for x2:"X, Y or Z")
> }
>
> This loop creates 9 graphs and the titles and xtitles I expect should be:
> 1) A X
> 2) A Y
> 3) A Z
> 4) B X
> 5) B Y
> 6) B Z
> 7) C X
> 8) C Y
> 9) C Z
>
> My question is: how can I call each of the labels of x1 and x2 into the
> graph sintax in the loop?
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index