I'd appreciate any suggestions on importing csv data into Stata, where the data comes in 2 separate csv files containing i) the data and ii) the dictionary/codebook. (It is data from weather stations within the MetDB database, in case anyone is interested - but the problem/task is general.)
The main data file is relatively straightforward and contains a number of variables, each of which is identified simply by a column number. E.g.:
The "dictionary" file - I hesitate to call it that since a .dct file is something specific and not this - contains information on the variable name (metdb_short_name) of each column number in the main data file, the corresponding variable label (long_name), and the value label information where appropriate (flag_values and flag_meanings). E.g.:
My instinct is to try to create 3 different tempfiles (one for each of varnames, varlabs, and value labels), and then try to use those to loop over the data and assign them using the usual rename, label variable etc. commands. Any suggestions?
Thanks very much in advance!
The main data file is relatively straightforward and contains a number of variables, each of which is identified simply by a column number. E.g.:
1 | 2 | 3 | |
2017 | -80.367 | 0 | |
2017 | -76.417 | 1 | |
2017 | -73.633 | 2 |
The "dictionary" file - I hesitate to call it that since a .dct file is something specific and not this - contains information on the variable name (metdb_short_name) of each column number in the main data file, the corresponding variable label (long_name), and the value label information where appropriate (flag_values and flag_meanings). E.g.:
long_name | 1 | Year | ||
type | 1 | int | ||
metdb_short_name | 1 | YEAR | ||
long_name | 2 | Latitude | ||
type | 2 | int | ||
metdb_short_name | 2 | LTTD | ||
long_name | 3 | Station type | ||
type | 3 | int | ||
metdb_short_name | 3 | STTN_RPRT_TYPE | ||
flag_values | 3 | 0 | 1 | 2 |
flag_meanings | 3 | Automatic | Manned | Hybrid: both manned and automatic |
My instinct is to try to create 3 different tempfiles (one for each of varnames, varlabs, and value labels), and then try to use those to loop over the data and assign them using the usual rename, label variable etc. commands. Any suggestions?
Thanks very much in advance!
Comment