Skip to content

Instantly share code, notes, and snippets.

@iangow
Last active May 21, 2016 14:47
Show Gist options
  • Save iangow/e1fae43bb3a21d53d5703ee754caa421 to your computer and use it in GitHub Desktop.
Save iangow/e1fae43bb3a21d53d5703ee754caa421 to your computer and use it in GitHub Desktop.
Code to identify data files that Stata loads or saves
#!/usr/bin/env perl
# Get do file
@lines = <STDIN>;
# Get files used
foreach my $line (@lines) {
if ($line =~ /(?:use|(?:merge|joinby).*using)\s+"?(\w+)/) {
push @stata_files, $1;
}
}
my %hash = map { $_ => 1 } @stata_files;
my @unique = keys %hash;
print "**Files used**:\n";
foreach my $stata_file (sort @unique) {
print "$stata_file\n";
}
# Get files saved
foreach my $line (@lines) {
if ($line =~ /(?:save|saveold)\s+(\w+)/) {
# print($line);
push @stata_files_saved, $1;
}
}
my %hash = map { $_ => 1 } @stata_files_saved;
my @unique = keys %hash;
print "\n**Files created**:\n";
foreach my $stata_file (sort @unique) {
print "$stata_file\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment