Announcement

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

  • Value Label on states

    I am trying to make a variable (state_num) for the 50 states and D.C. where Alabama ==1, Alaska ==2, etc. I have the variable "state" where they are all listed by name. Is there a quicker way to do this than replace state_num=1 if state=="Alabama". I could have done that in the time it's taken me to try and figure this out, but I am trying to learn the tips and tricks. I have been out of the stata game for some time now and trying to relearn. Thank you!

  • #2
    The encode command should give you what you want, see the output of help encode for details.

    Comment


    • #3
      Perhaps statastates (from SSC) will do what you ask. However, I've never used it.

      Code:
      package statastates from http://fmwww.bc.edu/repec/bocode/s
      ----------------------------------------------------------------------------------------------------------
      
      TITLE
            'STATASTATES': module to add US state identifiers to dataset
      
      DESCRIPTION/AUTHOR(S)
            
             statastates is a simple Stata module for adding U.S. state
            identifiers (abbreviation, name, and FIPS code) that may be
            missing from your dataset.
            
            KW: data management
            KW: US states
            
            Requires: Stata version 10
            
            Distribution-Date: 20180110
            
            Author: William L. Schpero, Yale University
            Support: email [email protected]
            
      
      INSTALLATION FILES                          (type net install statastates)
            statastates.ado
            statastates.sthlp
            statastates_data.ado
      ----------------------------------------------------------------------------------------------------------
      (type ssc install statastates to install)

      Comment


      • #4
        Thank you! I used encode and it was super easy!

        Comment

        Working...
        X