*! version 1.0.13 10oct2019
help dta2md

Title

dta2md -- Convert Stata system file to metadata

Table of contents

Syntax
Description
Known issues
Examples
Acknowledgements
Author

Syntax

dta2md input(filename) freqvarlist(varlist) output(filename) [group(varname) replace missingdef(exp) smissingdef(exp) relation(re)]

Arguments

input specifies the Stata system file which is converted.

freqvarlist list of variables for which information on value level is computed.

output specifies where the metadata file is saved.

group specifies group variable across which meta data are stratified.

replace specifies if output file replaces existing file.

missingdeff specifies definition which non-system-missings in numerical variables should be considered as invalid values.

smissingdeff specifies definition which non-system-missings in alpha-numeric variables should be considered as invalid values.

relation specifies a regular expression which is used to indicate
related variables of main variables. E.g. the suffix _flag indicates flag variables of the respective variables without the suffix. This relation would be specified with relation("(_flag)$").

Description

dta2md converts a Stata system file to aggregated metadata. For all variables,
descriptive statistics are computed. Additionally, for a specified subset of variables, frequencies on the value level can be generated.
The ado allows to generate all metadata for the whole sample and also for all levels of a categorical variable.
Exemplatory use cases might be international comparative data.

Known issues

Continuous variables: In the metadata file, a observation for each level of an variable in the list freqvarlist is created.
This leads to a huge metadata file if continuous variables are accidentally included in the list freqvarlist. Therefore, do not include continuous variables.

Encoding problems: The ado does not guarantee proper translation between encoding. If you run into problems, use [D] unicode translate to convert your system file, before you use the ado.

Missing values: The ado uses system missings to compute the number of valid cases and respective percentages of all cases. The options missingdeff and smissingdeff can be used to
specify missing values. This missing option functionality is designed for identical system missing structure for all variables, e.g. all negative values should be considered as system missings.
It is possible to specify missing definition that differentiate along variables, but the ado is finally tested for such applications. We advise to use consistent missing definitions.

Examples

This is simple application of the ado to convert the auto data to metadata. Here, we only compute frequencies for the variables rep78. We use foreign as group variable, i.e. we get all statistics
also for domestic and foreign cars separately. In the missing option, we define that all negative values in numeric variable should be considered as system missing.

. dta2md, input(`c(sysdir stata)'auto.dta) output("auto_md.dta") freqvarlist(rep78) group(foreign) missingdef(`"(X < 0) | missing(X)"') smissingdef(missing(X)) replace
Variables processed (12)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
............

. use auto_md.dta

. list in 1/20, sepby(varName)

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| group computed varName variableLabel total_n total_~g min max Mean Standa~n value valueL~l n percent validP~t isValid first |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1. | all 0 make Make and Model 74 0 . . . . . . . . 1 |
2. | DOM 0 make Make and Model 52 0 . . . . . . . . 1 |
3. | FOR 0 make Make and Model 22 0 . . . . . . . . 1 |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
4. | all 0 price Price 74 0 3291 15906 6165.257 2949.496 . . . . 1 |
5. | DOM 0 price Price 52 0 3291 15906 6072.423 3097.104 . . . . 1 |
6. | FOR 0 price Price 22 0 3748 12990 6384.682 2621.915 . . . . 1 |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7. | all 0 mpg Mileage (mpg) 74 0 12 41 21.2973 5.785503 . . . . 1 |
8. | DOM 0 mpg Mileage (mpg) 52 0 12 34 19.82692 4.743297 . . . . 1 |
9. | FOR 0 mpg Mileage (mpg) 22 0 14 41 24.77273 6.611187 . . . . 1 |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
10. | all 1 rep78 Repair Record 1978 74 5 1 5 3.405797 .9899323 1 2 2.702703 2.898551 1 1 |
11. | all 1 rep78 Repair Record 1978 74 5 1 5 3.405797 .9899323 2 8 10.81081 11.5942 1 0 |
12. | all 1 rep78 Repair Record 1978 74 5 1 5 3.405797 .9899323 3 30 40.54054 43.47826 1 0 |
13. | all 1 rep78 Repair Record 1978 74 5 1 5 3.405797 .9899323 4 18 24.32432 26.08696 1 0 |
14. | all 1 rep78 Repair Record 1978 74 5 1 5 3.405797 .9899323 5 11 14.86487 15.94203 1 0 |
15. | DOM 1 rep78 Repair Record 1978 52 4 1 5 3.020833 .837666 1 2 3.846154 4.166667 1 1 |
16. | DOM 1 rep78 Repair Record 1978 52 4 1 5 3.020833 .837666 2 8 15.38461 16.66667 1 0 |
17. | DOM 1 rep78 Repair Record 1978 52 4 1 5 3.020833 .837666 3 27 51.92308 56.25 1 0 |
18. | DOM 1 rep78 Repair Record 1978 52 4 1 5 3.020833 .837666 4 9 17.30769 18.75 1 0 |
19. | DOM 1 rep78 Repair Record 1978 52 4 1 5 3.020833 .837666 5 2 3.846154 4.166667 1 0 |
20. | FOR 1 rep78 Repair Record 1978 22 1 3 5 4.285714 .7171372 3 3 13.63636 14.28571 1 1 |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

In the second example, we also use the option relation to define dependencies among variables, in order to distinguish attached variables from main variables.
We again use the auto.dta, but let's assume the length is the flag variable related to weight. To indicate this, the variable name is weight_flag.
In such a case, we would add the the option relation("(_flag)$"). For illustration we change the auto file accordingly.

. sysuse auto.dta, clear
(1978 Automobile Data)

. rename length weight_flag

. save auto.dta, replace
file auto.dta saved

. dta2md, input(`c(sysdir stata)'auto.dta) output("auto_md.dta") freqvarlist(rep78) group(foreign) missingdef(`"(X < 0) | missing(X)"') smissingdef(missing(X)) relation("(_flag)$") replace
Variables processed (12)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
............

. list in 29/34, sepby(varName)

+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| group computed varName mother variableLabel total_n total_~g min max Mean Standa~n value valueL~l n percent validP~t isValid first |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
29. | all 0 weight Weight (lbs.) 74 0 1760 4840 3019.459 777.1935 . . . . 1 |
30. | DOM 0 weight Weight (lbs.) 52 0 1800 4840 3317.115 695.3638 . . . . 1 |
31. | FOR 0 weight Weight (lbs.) 22 0 1760 3420 2315.909 433.0034 . . . . 1 |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
32. | all 0 weight_flag weight Length (in.) 74 0 142 233 187.9324 22.26634 . . . . 1 |
33. | DOM 0 weight_flag weight Length (in.) 52 0 147 233 196.1346 20.04605 . . . . 1 |
34. | FOR 0 weight_flag weight Length (in.) 22 0 142 193 168.5455 13.68255 . . . . 1 |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

The variable mother indicates that weight is the relational superordinate partner to weight_flag.
Typical use cases would me additional variable that indicate the origin of missing values and flag variables that mark imputed values.

Acknowledgments

Florian Thirolf, Anne Balz

Author

Klaus Pforr, GESIS, klaus.pforr@gesis.org