DTA
application/x-stata-dta
Magic Bytes
Offset: 0
3C 73 74 61 74 61 5F 64 74 61 3E 3C 68 65 61 64 65 72 3E 3C 72 65 6C 65 61 73 65 3E
The Stata Data File (DTA) is a proprietary binary format created and maintained by StataCorp for its statistical analysis software. Researchers in fields such as economics, sociology, and political science utilize it to store structured datasets, variable labels, and comprehensive metadata for quantitative analysis. As a data-only format, it is considered safe from execution risks, though modern versions employ a specific XML-like header to ensure cross-platform compatibility and structural integrity.
Validation Code
How to validate .dta files in Python
Python
def is_dta(file_path: str) -> bool:
"""Check if file is a valid DTA by magic bytes."""
signature = bytes([0x3C, 0x73, 0x74, 0x61, 0x74, 0x61, 0x5F, 0x64, 0x74, 0x61, 0x3E, 0x3C, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x3E, 0x3C, 0x72, 0x65, 0x6C, 0x65, 0x61, 0x73, 0x65, 0x3E])
with open(file_path, "rb") as f:
return f.read(28) == signature
How to validate .dta files in Node.js
Node.js
function isDTA(buffer: Buffer): boolean {
const signature = Buffer.from([0x3C, 0x73, 0x74, 0x61, 0x74, 0x61, 0x5F, 0x64, 0x74, 0x61, 0x3E, 0x3C, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x3E, 0x3C, 0x72, 0x65, 0x6C, 0x65, 0x61, 0x73, 0x65, 0x3E]);
return buffer.subarray(0, 28).equals(signature);
}
Go
func IsDTA(data []byte) bool {
signature := []byte{0x3C, 0x73, 0x74, 0x61, 0x74, 0x61, 0x5F, 0x64, 0x74, 0x61, 0x3E, 0x3C, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x3E, 0x3C, 0x72, 0x65, 0x6C, 0x65, 0x61, 0x73, 0x65, 0x3E}
if len(data) < 28 {
return false
}
return bytes.Equal(data[:28], signature)
}
API Endpoint
GET
/api/v1/dta
curl https://filesignature.org/api/v1/dta