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]

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

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

Subject |
st: RE: RE: RE: Saving different parts of a dataset using foreach |

Date |
Tue, 31 Aug 2010 12:02:40 +0200 |

<> So if only Matthew had used the word "numlist" instead of "year", his syntax would have been legal: *********** foreach i of numlist 2002/2008 { di `i' } *********** -forvalues- still looks simpler to me... HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: Dienstag, 31. August 2010 11:29 To: 'statalist@hsphsun2.harvard.edu' Subject: st: RE: RE: Saving different parts of a dataset using foreach In other words, only certain keywords may appear after -of-. The relevant syntax is foreach <lname> of <listtype> <list> { commands referring to `lname' } -- and the only allowed -listtype-s are local global varlist newlist numlist Nick n.j.cox@durham.ac.uk Martin Weiss Look at the -foreach- syntax diagram, or read up on it in NJC`s http://www.stata-journal.com/sjpdf.html?articlenum=pr0005. Even better: -forvalues- *********** forv year = 2002/2008{ di `year' } *********** Matthew Krauchunas I am working with panel data and I need to separate the data by year, run some commands, and then append it. The BY command will not work with this particular command so that is not an option. I have tried the following commands and it keeps telling me invalid syntax. Does anyone see an error here or have a suggestion(s)? use "G:\Merged_Joined_Appended files\final_oshpd_oscar_merge_w_dp_first_set_variables" sort year cd g:\Years preserve foreach i of year 2002/2008 { keep if year == `i' * run my commands here * save year_`i' restore, preserve } * * 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/

**Follow-Ups**:**st: RE: RE: RE: RE: Saving different parts of a dataset using foreach***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: Saving different parts of a dataset using foreach***From:*Matthew Krauchunas <krauchunasms@mymail.vcu.edu>

**st: RE: Saving different parts of a dataset using foreach***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: RE: RE: Saving different parts of a dataset using foreach***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st:about the fixed-effects model** - Next by Date:
**st: RE: RE: RE: RE: Saving different parts of a dataset using foreach** - Previous by thread:
**st: RE: RE: Saving different parts of a dataset using foreach** - Next by thread:
**st: RE: RE: RE: RE: Saving different parts of a dataset using foreach** - Index(es):