Topic: Using a .dct file to read data into Stata
Background
==========
The datasets in a standard HRS product distribution kit are contained in
ASCII files with a .DA suffix. SAS, SPSS, and Stata command files are
supplied for each .DA file, allowing the user to read the data into the
statistical analysis system of her/his choice. In the case of the HRS 2002
County Geographic Information files, the following table cross-references
the Stata command file (.dct) suffix with the appropriate .DA file:
Product Command File Data File
---------- ------------ -----------
1993 AHEAD ahd1cty.dct ahd1cty.da
1995 AHEAD ahd2cty.dct ahd2cty.da
1992 HRS hrs1cty.dct hrs1cty.da
1994 HRS hrs2cty.dct hrs2cty.da
1996 HRS hrs3cty.dct hrs3cty.da
1998 HRS hrs98cty.dct hrs98cty.da
2000 HRS hrs00cty.dct hrs00cty.da
2002 HRS hrs02cty.dct hrs02cty.da
Reading the Data
================
How to read the data into Stata:
We will use as an example the 2002 HRS .dct and .da files for the county
geocode data. We assume that:
1. The .dct files are stored in the following location:
c:\hrs\resdat\geocode\2002\county\stata
2. The .da files are stored in the following location:
c:\hrs\resdat\geocode\2002\county\data
The file hrs02cty.dct contains the following information:
-----------------------------------cut here---------------------------------
infile dictionary using c:\hrs\resdat\geocode\2002\county\data\HRS02cty.da {
* HRS 2002
_column(1) str6 HHID %6s "Household ID"
_column(7) str3 PN %3s "Person Number"
_column(10) str2 StUSPS %2s "USPS State Abbreviation"
_column(12) str2 StFIPS %2s "FIPS State Code"
_column(14) str3 CtyFPS %3s "FIPS County Code"
_column(17) str5 StCty %5s "State+County FIPS Code"
_column(22) str30 County %30s "Name of County"
_column(52) str1 MatchTyp %1s "Match Quality Indicator"
}
-----------------------------------cut here---------------------------------
In order to read the information contained in the .da file into Stata, begin
by opening your Stata application. (If it is already open, be sure to type
'clear' before you do anything more.) Next you should type the following command:
infile using c:\hrs\resdat\geocode\2002\county\stata\HRS02cty.dct
This should result in the county file for 2002 being read into Stata.
It is important to note that you will need to modify the file locations if you
have unzipped the files into sub-directories that are different than the default
sub-directories referenced in the distribution files. For example, if you have
saved the .da files in sub-directory c:\hrs\data and the .dct files in sub-directory
c:\hrs\stata, you will need to modify the first line of c:\hrs\stata\HRS02cty.dct
file to read...
infile dictionary using c:\hrs\data\HRS02cty.da
Once in stata, issue the following command...
infile using c:\hrs\stata\HRS02cty.dct
This should provide the desired result.
Click here to close this window
|