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: Combining graphs addendum


From   Ronnie Babigumira <[email protected]>
To   [email protected]
Subject   Re: st: Combining graphs addendum
Date   Wed, 12 Feb 2014 09:40:11 +0100

Hi Paul,
Yesterday I missed the obvious `i'+1 was increasing with each variable.

This works on for me (Stata/MP 13.1 on Windows 7)

sysuse auto, clear
local i = 1
foreach v of varlist weight length {
              scatter price `v', name(panel_`i')
              local i=`i'+1
}

graph combine panel1 panel2

Question: Does it work if instead of numbers, the graphs are named
after the variables?

sysuse auto, clear
foreach v of varlist weight length {
      scatter price `v', name(panel_`v')
}

graph combine panel_weight panel_length

Ronnie


On Wed, Feb 12, 2014 at 2:43 AM, Paul <[email protected]> wrote:
> Testing your guess, I put an extra "graph describe" before "local
> i=`i'+1".
>
> It shows that each graph with the correct name is in memory before the
> counter is increased by 1, and each graph flashes quickly on the screen.
>
> But at the end of the final loop, only panel3 is in memory.
>
> I summed the three HIP* variables as you suggested. The data are all there.
>
> Paul Gross
>
>
>
> On 12/02/14 11:57 AM, "Nick Cox" <[email protected]> wrote:
>
>>I don't understand what is going on but my wild guess is that -panel1-
>>and -panel2- are never being produced at all.
>>
>>Try
>>
>>su HIP1824Px HIP1836Px HIP1819Px
>>
>>su HIP1824Px HIP1836Px HIP1819Px if LOS>0 & hospital_group=="" ///
>>& separation_fy=="2010/11"
>>
>>Nick
>>[email protected]
>>
>>
>>On 12 February 2014 00:47, Paul <[email protected]> wrote:
>>> Thank you Nick. Your more elegant code produced the error message shown
>>> below the code.
>>>
>>> ******************
>>> local pre graph bar total_episd_amt if LOS>0 & hospital_group=="" ///
>>> & separation_fy=="2010/11", ///
>>> over (COMPTOT, relabel(2 "Complication" 1 "NoComplication"))
>>>
>>> local i=1
>>> foreach v of varlist HIP1824Px HIP1836Px HIP1819Px {
>>>
>>> `pre' over(`v', relabel(2 "`v'"  1 "Other admissions")) ///
>>> title("Mean episode amount overnight stays, public hospitals 2010/11")
>>>///
>>> subtitle("`v' with/without complications") name(panel`i', replace)
>>>
>>> local i=`i'+1
>>> }
>>>
>>> graph describe panel1
>>> graph describe panel2
>>> graph describe panel3
>>>
>>> graph combine panel1 panel2 panel3
>>>
>>> ********************
>>>
>>> Error message: "graph panel1 not found"
>>>
>>>
>>> **********************
>>>
>>> My subsequent "graph describe" shows that only panel3 is in memory, so
>>> your first two "graph describe panel1" and "graph describe panel2" found
>>> nothing to describe.
>>>
>>> Something is eating my first two graphs.
>>>
>>> Paul Gross
>>>
>>> On 12/02/14 7:51 AM, "Nick Cox" <[email protected]> wrote:
>>>
>>>>This thread is all tangled up.
>>>>
>>>>First off, -name()- specifies a graph name, and contrary to Rich's
>>>>suggestion, you should not add ".gph" in the subsequent -graph
>>>>combine- call.
>>>>
>>>>Please
>>>>
>>>>1. Ensure that your code is run from one and only one place. Don't mix
>>>>do-file and interactive statements, just in case you have been doing
>>>>that.
>>>>
>>>>2. Try this (each /// should appear at the end of a line)
>>>>
>>>>local pre graph bar total_episd_amt if LOS>0 & hospital_group=="" ///
>>>>& separation_fy=="2010/11", ///
>>>>over (COMPTOT, relabel(2 "Complication" 1 "NoComplication"))
>>>>
>>>>local i=1
>>>>foreach v of varlist HIP1824Px HIP1836Px HIP1819Px {
>>>>
>>>> `pre' over(`v', relabel(2 "`v'"  1 "Other admissions")) ///
>>>> title("Mean episode amount overnight stays, public hospitals 2010/11")
>>>>///
>>>> subtitle("`v' with/without complications") name(panel`i', replace)
>>>>
>>>>local i=`i'+1
>>>>}
>>>>
>>>>graph describe panel1
>>>>graph describe panel2
>>>>graph describe panel3
>>>>
>>>>graph combine panel1 panel2 panel3
>>>>
>>>>
>>>>
>>>>
>>>>Nick
>>>>[email protected]
>>>>
>>>>
>>>>On 11 February 2014 20:36, Paul <[email protected]> wrote:
>>>>> Thank you Rich but the coding below produced another error message:
>>>>>
>>>>> "file panel1.gph not found"
>>>>>
>>>>> local i=1
>>>>> foreach v of varlist HIP1824Px HIP1836Px HIP1819Px {
>>>>> graph bar total_episd_amt if LOS>0 & hospital_group=="" &
>>>>> separation_fy=="2010/11", over (COMPTOT, relabel(2 "Complication" 1
>>>>> "NoComplication")) over(`v', relabel(2 "`v'"  1 "Other admissions"))
>>>>>title
>>>>> ("Mean episode amount overnight stays, public hospitals 2010/11")
>>>>>subtitle
>>>>> ("`v' with/without complications") name(panel`i')
>>>>> local i=`i'+1
>>>>> }
>>>>>
>>>>> graph combine panel1.gph panel2.gph panel3.gph,cols(1)
>>>>>
>>>>> My loop with the local `i' is sending graphs into a void or
>>>>>overwriting
>>>>> them
>>>>>
>>>>> Any more suggestions please?
>>>>>
>>>>> Paul
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 12/02/14 12:06 AM, "Richard Goldstein" <[email protected]>
>>>>>wrote:
>>>>>
>>>>>>you need to add ".gph" to your names in your "graph combine" line
>>>>>>
>>>>>>Rich
>>>>>>
>>>>>>On 2/10/14, 10:06 PM, Paul wrote:
>>>>>>> Sorry, I omitted the graph combine code
>>>>>>>
>>>>>>> I have a very large file of 2.3 million hospital admissions, and am
>>>>>>> using stata v 13.1 on a MacBook Pro
>>>>>>>
>>>>>>> I want to create three bar charts of the hospital cost of
>>>>>>>complications
>>>>>>> for hip replacement, using three different icd codes for the hip
>>>>>>> procedures. I want to then  combine the three in one graph.
>>>>>>>
>>>>>>> This seemed straightforward with the following loop:
>>>>>>>
>>>>>>>
>>>>>>> gen i=1
>>>>>>> foreach v of varlist HIP1824Px HIP1836Px HIP1819Px {
>>>>>>>  graph bar total_episd_amt if LOS>0 & hospital_group=="" &
>>>>>>> separation_fy=="2010/11", over (COMPTOT, relabel(2 "Complication" 1
>>>>>>> "NoComplication")) over(`v', relabel(2 "`v'"  1 "  Other
>>>>>>>admissions"))
>>>>>>> title ("Mean episode amount overnight stays, public hospitals
>>>>>>>2010/11")
>>>>>>> subtitle ("`v' with/without complications") name(HIP`i')
>>>>>>>  replace i=i+1
>>>>>>>  }
>>>>>>> graph combine HIP1 HIP2 HIP3,cols(1)
>>>>>>>
>>>>>>> The error message is : HIP1 is not a memory graph
>>>>>>>
>>>>>>> I have tried various combinations of the saving and name
>>>>>>>conventions,
>>>>>>> including double quotation marks around the `i' in the name, but
>>>>>>>none
>>>>>>>work.
>>>>>>>
>>>>>>> Any  ideas, please?
>>>>>>>
>>>>>>*
>>>>>>*   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/
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> *
>>>>> *   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/
>>>>*
>>>>*   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/
>>>
>>>
>>>
>>>
>>> *
>>> *   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/
>>*
>>*   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/
>
>
>
>
> *
> *   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/
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index