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: Need help understanding stata graphics from http://www.survey-design.com.au/Stata%20Graphs.html.
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Need help understanding stata graphics from http://www.survey-design.com.au/Stata%20Graphs.html.
Date
Mon, 8 Jul 2013 14:39:14 +0100
The syntax you ask about is mostly not specific to graphics, so I've
edited the post down to the core question.
-help macro- indicates that one syntax has the form
`= exp'
where as usual exp is Stata's generic syntax for an expression
(something that can be evaluated). For example, in
`= 2+2'
the exp is the expression
2 + 2
The general pattern here is a twofold instruction: first evaluate the
expression and then use the result of the expression. So, if presented
with 2 + 2 as an expression within this syntax, Stata would evaluate
it and place the result 4 at the position indicated.
In terms of your questions 1)...3)
1) What is the utility of the -foreach- loop?
There is no -foreach- loop. The -forvalues- loop loops over the
observed values of the variable -x- which are the bar midpoints for
the histogram.
2) What does the notation i=1/`=r(N)' mean? Typically I see macros
like `r(N)'
`=r(N)' is another example of the `=exp' syntax. The expression is
r(N) and the `= ' force evaluation. `r(N)' would in fact work
equally well here.
3) How does local label `label' `=string(x[`i'],"%8.2f")' work?
In a loop, take each bar midpoint and format it with two decimal
places. The syntax uses yet another example of `=exp' and is
schematically
local label `label' `=exp'
where exp is
string(x[`i'],"%8.2f")
which is an expression yielding a string result. The loop builds up a
list of labels for the x axis containing the bar midpoints, displayed
with two decimal places.
Nick
[email protected]
Michael Stewart [edited]
> count if !missing(x)
> forvalues i=1/`=r(N)' {
> local label `label' `=string(x[`i'],"%8.2f")'
>
> }
>
> histogram mpg , bin(6) xlabel(`label')
> I can't understand Stata commands after "count if !missing(x)"
>
> 1) What is the utility of the -foreach- loop?
> 2) What does the notation i=1/`=r(N)' mean? Typically I see macros
> like `r(N)'
> 3) How does local label `label' `=string(x[`i'],"%8.2f")' work?
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/