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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

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

Subject |
RE: st: using postfile in a loop |

Date |
Tue, 10 Nov 2009 00:14:12 +0100 |

<> ******* sysuse auto, clear su mpg gen varformpg=r(max) ******* You could also store it as a -local- macro (local mpgmax=r(max))... HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Kushan Thakkar Sent: Dienstag, 10. November 2009 00:11 To: statalist@hsphsun2.harvard.edu Subject: Re: st: using postfile in a loop Thanks Martin One quick (and rather rookie) question: when I am using r-class resule (such as r(max) ) is there a way to store this value into a constant variable and then use that variable instead ? Thanks again for FAQ. On Mon, Nov 9, 2009 at 5:58 PM, Martin Weiss <martin.weiss1@gmx.de> wrote: > > <> > > Sure, this is an "implicit" loop, sorry about that! > > You would loop over the distinct values of variables as in the FAQ cited > earlier... > > > HTH > Martin > > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Kushan Thakkar > Sent: Montag, 9. November 2009 23:53 > To: statalist@hsphsun2.harvard.edu > Subject: Re: st: using postfile in a loop > > I meant to say that if I have the following data, > > cusip date ticker prc > > If I do gen newvar, it would automatically do it for all the > datapoints (hence gen command has a built-in loop). > > However, I want to know how can I do the same by using an actual > foreach loop that loops over cusip or data variable. > > Thanks > > On Mon, Nov 9, 2009 at 5:40 PM, Martin Weiss <martin.weiss1@gmx.de> wrote: >> >> <> >> >> http://www.stata.com/support/faqs/data/foreach.html >> >> >> >> What do you mean by " gen variable with built-in loop"? >> >> HTH >> Martin >> >> -----Original Message----- >> From: owner-statalist@hsphsun2.harvard.edu >> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Kushan Thakkar >> Sent: Montag, 9. November 2009 23:34 >> To: statalist@hsphsun2.harvard.edu >> Subject: Re: st: using postfile in a loop >> >> Thanks everyone for calling me out on the no loop part. >> >> On a different note, how can I loop on a single variable ? For >> example, let's say if I wanted to loop over the date variable and then >> over the cusip variable, how would I go about doing this? I understand >> that there is no need to explicitly create loop since I can use gen >> variable with built-in loop. However, I want to do this so that I can >> understand how loops and postfile work with each other. >> >> Thanks. >> >> On Mon, Nov 9, 2009 at 5:14 PM, Maarten buis <maartenbuis@yahoo.co.uk> >> wrote: >>> --- On Mon, 9/11/09, Kushan Thakkar wrote: >>>> I have a dataset the contains the following data: >>>> >>>> cusip ticker date prc ....(few more variables).... RminusI >>>> >>>> I need to isolate data points for which RminusI is less >>>> than its first decile and then post these data points in a >>>> different file. >>> >>> This is not a case for -postfile- or a loop. In the example >>> below nlsw88.dta is your master data, grade is your id variable, >>> and wage is your RminusI variable. >>> >>> *---------- begin example -------------- >>> sysuse nlsw88, clear >>> bys grade: egen lb = pctile(wage), p(10) >>> keep if wage < lb >>> *------------ end example -------------- >>> ( For more on how to use examples I sent to statalist see: >>> http://www.maartenbuis.nl/stata/exampleFAQ.html ) >>> >>> Hope this helps, >>> Maarten >>> -------------------------- >>> Maarten L. Buis >>> Institut fuer Soziologie >>> Universitaet Tuebingen >>> Wilhelmstrasse 36 >>> 72074 Tuebingen >>> Germany >>> >>> http://www.maartenbuis.nl >>> -------------------------- >>> >>> >>> >>> >>> >>> >>> >>> * >>> * 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/ > > > * > * 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/

**References**:**st: using postfile in a loop***From:*Kushan Thakkar <kthakk4@gmail.com>

**Re: st: using postfile in a loop***From:*Maarten buis <maartenbuis@yahoo.co.uk>

**Re: st: using postfile in a loop***From:*Kushan Thakkar <kthakk4@gmail.com>

**Re: st: using postfile in a loop***From:*Kushan Thakkar <kthakk4@gmail.com>

**Re: st: using postfile in a loop***From:*Kushan Thakkar <kthakk4@gmail.com>

- Prev by Date:
**Re: st: Non-normally distributed dependent variable for Random-Intercept Model and 2SLS** - Next by Date:
**Re: st: using postfile in a loop** - Previous by thread:
**Re: st: using postfile in a loop** - Next by thread:
**st: Non-normally distributed dependent variable for Random-Intercept Model and 2SLS** - Index(es):

© Copyright 1996–2023 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |