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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Singeling out datasets containing variable X in folder with many stata files


From   Eric Booth <ebooth@ppri.tamu.edu>
To   "<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Singeling out datasets containing variable X in folder with many stata files
Date   Tue, 14 Jun 2011 15:25:33 +0000

<>

Sorry, 2 of the 3 urls in my previous message were to the same thread -- I meant to include a link to this thread showing how to loop over directories and subdirectories:
http://www.stata.com/statalist/archive/2010-01/msg00239.html

Also, if you do decide to move files to sub-directories, become familiar with the -copy- and -rm- commands.

- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu


On Jun 14, 2011, at 10:17 AM, Eric Booth wrote:

> <>
> 
> On Jun 14, 2011, at 6:14 AM, Lukas Maximilian Rudolph wrote:
> 
>> Dear Statalisters,
>> 
>> I have a folder with many stata-files that I am about to merge. Some of these contain information on household level, some on individual level. Of these, some are are in wide, some are in long form.
>> 
>> I now want to identify all file names that contain a certain variable: 
>> I want to seperate all files with the variable "pidlink", the individual identifier.
>> Within these, I want to identify all files that contain a variable ending with "*type" as just these are in long form. 
>> 
>> Then I would be able to construct one loop that reshapes all datasets in long form and then another loop that merges all files on individual and household level automatically without going through every single file. 
> 
> There are some tips on using a global macro extended function and -descsave- (from SSC) to do something in a similar thread from a few days ago:
> http://www.stata.com/statalist/archive/2011-06/msg00538.html
> 
> Also see:  
> http://www.stata.com/statalist/archive/2011-06/msg00530.html
> http://www.stata.com/statalist/archive/2010-11/msg00113.html
> 
> These threads should help point you to ways to loop over files in a directory and identify variable names/types.  You'll notice that several of these examples include -append-, -merge- and/or -reshape- in the course of looping over the selected files in a directory (or sub-directory).
> 
> 
>> 
>> My thought would have been to try to save the files in different folders conditional on whether the respective variable is contained - but save is not combinable with "if".
>> 
>> Is there another way to sort these files out?
> 
> I don't think it's necessary to move these to different sub-folders conditional on their variable contents -- I would just change the dataset name to flag it.  So, change dataset1.dta to dataset1_hasmyvar.dta so that later you could still select all "dataset1_*" files with a macro as well as all "*_hasmyvar" files in another macro without having to tell the code to navigate over sub-folders.  However, that is just my preference, it's possible to work with the files either way.
> 
> - Eric
> 
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> ebooth@ppri.tamu.edu
> 
> *
> *   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