Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Label define for a variable with many observations

    Hello all,

    I am seeking help with the following. I have a dataset that is of population projections for each county in a state. There are 58 observations for the "county" variable, currently coded according to their FIPs (Federal Information Processing Standards) county code. For example, the value 6001 corresponds to Alameda county. The actual county names are only in the data dictionary. The dataset itself only has the FIPS codes.

    What I am trying to do is use the command "label define" to define a label named County so that instead of reading the value "6001" when I browse my data, I can read "Alameda." I have used "label define" before but only very simply (for example, label define Sex 0 "Female" 1 "Male"). The code I have so far is what follows:

    label define County 6001 "Alameda" 6003 "Alpine" 6005 "Amador" 6007 "Butte" 6009 "Calaveras" 6011 "Colusa" 6013 "Contra Costa"

    Do I have to complete this process for every single one of the 58 observations? Is there a simpler way or do I need to just import the data with the county names replacing the FIPS codes before I even begin working with Stata?

    Many thanks,
    Esi

  • #2
    I'm sending this from my phone, so we'll see how this works.

    I think you'll be better off just creating a table with FIPS codes and county names, and then just merging in based on the fips codes. That way you'll have both the FIPS code and the county name in your dataset should you need them in the future.


    Comment


    • #3
      As David mentioned, merge your data dictionary with your dataset. If you have a .dta file with the FIPS code and county name, just run
      Code:
       merge 1:1 fips_code using datadictionary.dta
      . This assumes your data is at the county-level.

      Now that you have both FIPS code and county name in the same dataset, you can write
      Code:
      labmask fips_code, values(county_name)
      to assign each FIPS code a value from its corresponding county name. You'll have install labmask as its a user-written command.

      Comment


      • #4
        Thank you! This was helpful.

        Comment

        Working...
        X