Last active
May 21, 2016 14:47
-
-
Save iangow/e1fae43bb3a21d53d5703ee754caa421 to your computer and use it in GitHub Desktop.
Code to identify data files that Stata loads or saves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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