Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Running loops with graphs


From   Eric Booth <eric.a.booth@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Running loops with graphs
Date   Fri, 27 Apr 2012 09:05:50 -0500

<>

Ok, so my loop should do what you are asking if you add `i' in as an [if] condition, e.g., 

******************
forvalues i = 1/51000 {
cap drop a b c   //or use -tempvar-
di `"`i'"' 

**i assume your oil well ID is called "oilwell"  below**
nl (WOR = {b0=0.1}*(1 * exp({b1=0.05}* (ageyear))))  if oilwell == `i'
predict a

nl log3: WOR ageyear if oilwell == `i'
predict b

nl gom3: WOR ageyear  if oilwell == `i'
predict c

twoway (scatter a y) (line a y, sort), legend(off) aspect(1) name(g1, replace)
twoway (scatter b y) (line b y, sort), legend(off) aspect(1) name(g2, replace)
twoway (scatter c y) (line c y, sort), legend(off) aspect(1) name(g3, replace)
gr combine g1 g2 g3, c(1) // change look of this combined graph with options
gr export "graph`i'.eps", as(eps) replace
}
******************

- Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754



On Apr 27, 2012, at 8:38 AM, Sebastian Galarza wrote:

> Eric, 
> 
> Thanks for your suggestions. I will try to clarify my problem so that you or others can better address the issue. I currently have a panel database organized by oil wells (i) with monthly data (WOR) for 50 years.  I want to run the goodness of fit tests for each oil well just as you suggested but I am not sure where to include i unless it would be something along the lines of by `"`i'"' : nl …. however this is the reason I thought about using the for values command. 
> 
> I hope this provides greater clarity and can serve others that encounter similar issues in the future. 
> 
> 
> Best, 
> 
> Sebastian
> 
> On Apr 26, 2012, at 5:05 PM, Eric Booth wrote:
> 
>> <>
>> 
>> You make reference to "i" without defining where it fits into your code, but assuming you know where "i" goes, here a (untested) code example that should do what you are asking with some adapting on your part.
>> 
>> ******************
>> forvalues i = 1/51000 {
>> 
>> di `"`i'"' //where does `i' plug-in in the equations below??
>> nl (WOR = {b0=0.1}*(1 * exp({b1=0.05}* (ageyear))))
>> predict a
>> 
>> nl log3: WOR ageyear
>> predict b
>> 
>> nl gom3: WOR ageyear 
>> predict c
>> 
>> twoway (scatter a y) (line a y, sort), legend(off) aspect(1) name(g1, replace)
>> twoway (scatter b y) (line b y, sort), legend(off) aspect(1) name(g2, replace)
>> twoway (scatter c y) (line c y, sort), legend(off) aspect(1) name(g3, replace)
>> gr combine g1 g2 g3, c(1) // change look of this combined graph with options
>> gr export "graph`i'.eps", as(eps) replace
>> }
>> ******************
>> ^ See -help forvalues- and -help graph combine- for more help.
>> 
>> 
>> 
>> - Eric
>> 
>> __
>> Eric A. Booth
>> Public Policy Research Institute 
>> Texas A&M University
>> ebooth@ppri.tamu.edu
>> +979.845.6754
>> 
>> 
>> 
>> 
>> 
>> On Apr 26, 2012, at 12:18 PM, Sebastian Galarza wrote:
>> 
>>> Hi, 
>>> 
>>> I am working on a large dataset and need to run different goodness of fit tests, graph these and save the graphs separately. I am not sure how to go about it. 
>>> 
>>> Basically, I want to run the following tests for up to 51000 values of i
>>> 
>>> nl (WOR = {b0=0.1}*(1 * exp({b1=0.05}* (ageyear))))
>>> predict a
>>> 
>>> nl log3: WOR ageyear
>>> predict b
>>> 
>>> nl gom3: WOR ageyear 
>>> predict c
>>> 
>>> I would ideally save this output for each value of i.  
>>> 
>>> twoway (scatter a y) (line a y, sort), legend(off) aspect(1)
>>> twoway (scatter b y) (line b y, sort), legend(off) aspect(1)
>>> twoway (scatter c y) (line c y, sort), legend(off) aspect(1)
>>> 
>>> I would ideally save these three graphs as one image for each value of i. 
>>> 
>>> Any help in doing this would be greatly appreciated. 
>>> 
>>> Best, 
>>> 
>>> Sebastian
>>> 
>>> 
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/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/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index