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: RE: RE: Saving different parts of a dataset using foreach


From   Matthew Krauchunas <krauchunasms@mymail.vcu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: Saving different parts of a dataset using foreach
Date   Mon, 30 Aug 2010 14:09:27 -0400

Thank you for your suggestions Martin.  I will append the files in the
next command after the forvalue loops.

Cheers,
Matt


On Mon, Aug 30, 2010 at 1:52 PM, Martin Weiss <martin.weiss1@gmx.de> wrote:
>
> <>
>
> Or rather
>
> ***********
> forv i = 2002/2008{
> ***********
>
> to avoid confusion with the variable "year".
>
> BTW, -keep-ing and -preserve-ing/-restore-ing is not the best way to achieve
> your goal. Just condition your "commands" with the -if- qualifier.
>
> Also, I cannot see where you actually -append- any data...
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss
> Sent: Montag, 30. August 2010 19:39
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: Saving different parts of a dataset using foreach
>
>
> <>
>
> 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'
> }
> ***********
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Matthew
> Krauchunas
> Sent: Montag, 30. August 2010 19:35
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Saving different parts of a dataset using foreach
>
> Hello,
>
> 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)?
>
> Thanks,
> Matt
>
> 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/
>
> *
> *   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