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: Preserve and restore within a foreach loop

From   Florian Seliger <>
Subject   st: Preserve and restore within a foreach loop
Date   Wed, 22 Dec 2010 15:07:53 -0700

Dear Statalist,

I want to restore a big dataset at the end of each iteration in order to save time ( I don't want to reload the 2,5GB file after each iteration), e.g.

use big_dataset.dta, clear

foreach file in ... {

joinby pat_var using "`file'"

drop pat_var


save changed_"`file'", replace
restore, preserve


The last command is intended to restore the big_dataset that should be matched with each file specified in the loop. Unfortunately, STATA interrupts the process and tells me that it does not find the variable pat_var.
Hence, the command might not work as intended, but I don't know where I have made a mistake.
Do you have any suggestions?

Thank you,

*   For searches and help try:

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