How to determine the Stata ds_format file from the command line?

I combined this one line Perl to define the Stata "ds_format" of some files ...

for file in *.dta; do perl -MParse::Stata::DtaReader -e 'open my $fileHandle, "<", @ARGV; my $dta = new Parse::Stata::DtaReader($fileHandle); print "$ARGV[0] is in STATA ds_format " . $dta->{ds_format} ,"\n\n";' $file; done

... but I guess you can use the stata command line command to get the same information. Here? Print script above for my files:

study1a.dta is located in STATA ds_format 113

study1b.dta is located in STATA ds_format 115

study2.dta is located in STATA ds_format 115

See also:

+4
source share
1 answer

Now you can simply read the first character of the file to determine the version. In addition to the version file version version 117 (current for Stata 13), the version will be saved in XML, so this method will need to be improved.

 file open fhandle using dataset.dta, read binary file read fhandle %1s firstbytechar file close fhandle if "`firstbytechar'"=="<"{ di "Version 117" } else { mata: st_numscalar("v", ascii("`firstbytechar'")) di "Version " v } 
+1
source

All Articles