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]

From |
Michael Stewart <michaelstewartresearch@gmail.com> |

To |
statalist <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Need help understanding stata graphics from http://www.survey-design.com.au/Stata%20Graphs.html. |

Date |
Mon, 8 Jul 2013 10:15:58 -0400 |

Dear Nick , Thanks a lot for your time and such detailed answers.They are very educational. Mike On Mon, Jul 8, 2013 at 9:39 AM, Nick Cox <njcoxstata@gmail.com> wrote: > 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 > njcoxstata@gmail.com > > 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/ -- Thank you , Yours Sincerely, Mike. * * 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/

**References**:**st: Need help understanding stata graphics from http://www.survey-design.com.au/Stata%20Graphs.html.***From:*Michael Stewart <michaelstewartresearch@gmail.com>

**Re: st: Need help understanding stata graphics from http://www.survey-design.com.au/Stata%20Graphs.html.***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**st: Modelling of categorical-continuous variable interaction - Follow-up** - Next by Date:
**Re: st: Creating a dummy dataset in Stata** - Previous by thread:
**Re: st: Need help understanding stata graphics from http://www.survey-design.com.au/Stata%20Graphs.html.** - Next by thread:
**Correction : st: Need help understanding stata graphics from http://www.survey-design.com.au/Stata%20Graphs.html.** - Index(es):