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: Looping over a range of observations


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Looping over a range of observations
Date   Fri, 23 Aug 2013 17:57:20 +0100

Assuming your stores have identifiers 1..900 then

forvalues i=1/90 {
local first = 10 * `i' - 9
local last = `first' + 9
histogram price1 if inrange(store, `first',  `Iast'), by(store)
graph save "graph`i'", replace
}

My guess is that you would find 12 or 16 graphs convenient, but the
arithmetic is easy to modify.

Nick
[email protected]


On 23 August 2013 17:48, Francesca Colantuoni <[email protected]> wrote:
> Hello Statalist!
> I am working with a panel data set. I would like to create and save
> graphs that show
> histograms of a variable (price1) per each store in the data set. I
> have many stores (900), therefore if I do:
>
> histogram price1, by (store)
>
> each histogram would be microscopic and I would not be able to see anything.
>
> So, I tried with:
>
> histogram price1 in 1/2120, by (store)
>
> which allows me to visualize histograms for the first 10 stores only,
> and this works way better.
>
> Now, though, I would like to create a loop that increments the range
> of observations and  creates a number of graphs containing 10
> histograms each.
>
> I was trying with something like:
>
> forvalues i=1/2120 {
> histogram price1 in `i', by(store)
> graph save graph "graph1.gph", replace
> }
>
> Of course I need to nest the loop to update the graphs and I still
> need to increment the range of observations, but for the moment, I
> would like to get some help to  figure out the first part, because
> even if the code runs no problem, the graph I get is not what I want
> (it's only one histogram with one bar).
>
> Kindest Regards,
>
> Francesca
> *
> *   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