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

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

 From Michael Stewart To statalist 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/
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.7681838,"math_prob":0.60570997,"size":3153,"snap":"2022-05-2022-21","text_gpt3_token_len":932,"char_repetition_ratio":0.10416005,"word_repetition_ratio":0.09430256,"special_character_ratio":0.31810975,"punctuation_ratio":0.16536662,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97853726,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-26T12:17:58Z\",\"WARC-Record-ID\":\"<urn:uuid:aa7b573e-2278-457f-b3d4-ab09b7b0ea5f>\",\"Content-Length\":\"11318\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5245559f-34a1-48a8-8c0d-02a0a2537bf3>\",\"WARC-Concurrent-To\":\"<urn:uuid:94748a22-ea5e-4f1e-837c-1c1c220fa13f>\",\"WARC-IP-Address\":\"66.76.6.5\",\"WARC-Target-URI\":\"https://www.stata.com/statalist/archive/2013-07/msg00235.html\",\"WARC-Payload-Digest\":\"sha1:UFCPRDCMSO4D2CN52M2TSK4AM2Q547UT\",\"WARC-Block-Digest\":\"sha1:OMWV4EVCHDSLX6CEUNFLNJPYOGWZNVYB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662604794.68_warc_CC-MAIN-20220526100301-20220526130301-00036.warc.gz\"}"}