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: Singeling out datasets containing variable X in folder with many stata files

From   Lukas Maximilian Rudolph <>
Subject   st: Singeling out datasets containing variable X in folder with many stata files
Date   Tue, 14 Jun 2011 13:14:57 +0200 (CEST)

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. 

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?

Many thanks,

Lukas Rudolph
University of Munich
Chair of International Economics

*Erroneous stata code:

file open mergedir using "${k}filelist.txt", read
file read mergedir linestore

while r(eof)==0 {
use `linestore'
capture confirm variable pidlink
save "${k}\individual\`linestore'" if _rc==0, replace /*prob: "if" incompatibel
save "${k}\household\`linestore'" if _rc==111, replace /*prob: "if" incompatibel
file read mergedir linestore
*   For searches and help try:

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