Announcement

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

  • Non-numeric String variable

    Hi All,

    I am new to Stata and getting hands on it by using the data. I have cross sectional data for around 90 countries, I want to create dummies for the Countries, but I am getting error that "string variables may not be used as factor variables"

    how can I address this problem.

    Thanks in advance if any one can help me with this.

  • #2
    Code:
    encode country, generate(cid) label(Countries)
    regress whatever i.cid // 90!
    Code:
    help encode

    Comment


    • #3
      Originally posted by Palana Bhatia View Post
      I have cross sectional data for around 90 countries
      Then I guess that you're not going to put them in as indicator variables into a regression model like I showed, huh. What are you going to do with them?.

      Comment


      • #4
        egen, group also has a lable option:

        Code:
        . sysuse auto
        (1978 Automobile Data)
        
        . egen mk = group(make), label
        
        . list mk make in 1/10
        
             +-------------------------------+
             |            mk   make          |
             |-------------------------------|
          1. |   AMC Concord   AMC Concord   |
          2. |     AMC Pacer   AMC Pacer     |
          3. |    AMC Spirit   AMC Spirit    |
          4. | Buick Century   Buick Century |
          5. | Buick Electra   Buick Electra |
             |-------------------------------|
          6. | Buick LeSabre   Buick LeSabre |
          7. |    Buick Opel   Buick Opel    |
          8. |   Buick Regal   Buick Regal   |
          9. | Buick Riviera   Buick Riviera |
         10. | Buick Skylark   Buick Skylark |
             +-------------------------------+
        
        . list mk make in 1/10, nol
        
             +--------------------+
             | mk   make          |
             |--------------------|
          1. |  1   AMC Concord   |
          2. |  2   AMC Pacer     |
          3. |  3   AMC Spirit    |
          4. |  7   Buick Century |
          5. |  8   Buick Electra |
             |--------------------|
          6. |  9   Buick LeSabre |
          7. | 10   Buick Opel    |
          8. | 11   Buick Regal   |
          9. | 12   Buick Riviera |
         10. | 13   Buick Skylark |
             +--------------------+
        
        .
        To manually generate dummies,

        Code:
        . tab make, gen(makedummy)
        
        . des make*
        
                      storage   display    value
        variable name   type    format     label      variable label
        ----------------------------------------------------------------------------------------------------
        make            str18   %-18s                 Make and Model
        makedummy1      byte    %8.0g                 make==AMC Concord
        makedummy2      byte    %8.0g                 make==AMC Pacer
        makedummy3      byte    %8.0g                 make==AMC Spirit
        makedummy4      byte    %8.0g                 make==Audi 5000
        makedummy5      byte    %8.0g                 make==Audi Fox
        makedummy6      byte    %8.0g                 make==BMW 320i
        makedummy7      byte    %8.0g                 make==Buick Century
        makedummy8      byte    %8.0g                 make==Buick Electra
        makedummy9      byte    %8.0g                 make==Buick LeSabre
        makedummy10     byte    %8.0g                 make==Buick Opel
        
        
        etc.

        Comment


        • #5
          The elaboration from Joseph Coveney in post #3 suggests that if indeed you have cross-sectional data, you may want to use the Stata XT commands designed for cross-sectional and longitudinal data. Take a look at the Stata Longitudinal-Data/Panel-Data Reference Manual PDF included with your Stata installation and accessible through Stata's Help menu.

          In any event, though, you will need a numeric version of your country identifier, as discussed above.

          Comment

          Working...
          X