Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: Saving different parts of a dataset using foreach

From   Matthew Krauchunas <>
Subject   st: Saving different parts of a dataset using foreach
Date   Mon, 30 Aug 2010 13:34:44 -0400


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
sort year
cd g:\Years
  foreach i of year 2002/2008 {
          keep if year == `i'
          * run my commands here *
          save year_`i'
          restore, preserve
*   For searches and help try:

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