Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: adding variables to a new data file
From
Steve Nakoneshny <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: adding variables to a new data file
Date
Tue, 12 Feb 2013 15:31:35 -0700
Hi David,
It isn't clear to me why you would need a loop in the first place to identify your variables of interest. Is the size of your dataset a limiting factor due to your version of Stata? Can you not simply keep a running tally of the variables you want to keep and export them en masse? Perhaps through the judicious use of a do file?
Steve
On 2013-02-12, at 3:21 PM, David Epstein wrote:
> Dear Stata-folks,
>
> This must be a really easy question to answer, but I'm feeling
> stumped. I have a data set with a large number of variables in it. I
> want to create a new data set with a subset of those variables, with
> the exact variables to be exported being read off a loop a few
> variables at a time.
>
> So for instance I first want to export the key identifying variable,
> which in my case is date. So I will:
>
> preserve
> keep date
> save temp, replace
> restore
>
> Then I'll loop through my loop once and get the names of five
> variables I want to add to temp, call them v1 v2 v3 v4 v5. The next
> time through, I'll get variables v6 through v10, and so on until I've
> added, say 50 variables to temp.
>
> My question is, what do my loops look like? Am I merging each time
> through? Keeping, say, date v1 v2 v3 v4 v5, merging, then restoring? I
> could, but that seems like it could take a while to keep preserving
> and restoring all the time. Plus, I keep having to save the temp file
> and then switch back to the master data set. Isn't there a command
> that says "take these variables from my current data set and add them
> to another data set?"
>
> Any help appreciated.
>
> David Epstein
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/