Announcement

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

  • Invalid syntax

    Hi, I have this variable lugnac_depart, which is the result of three variables.

    . tab lugnac_depart

    Departament |
    o de |
    Nacimiento | Freq. Percent Cum.
    ------------+-----------------------------------
    ._._11 | 163,490 69.54 69.54
    ._13_11 | 1,549 0.66 70.20
    ._15_11 | 10,876 4.63 74.82
    ._17_11 | 2,404 1.02 75.85
    ._18_11 | 570 0.24 76.09
    ._19_11 | 616 0.26 76.35
    ._20_11 | 917 0.39 76.74
    ._23_11 | 1,357 0.58 77.32
    ._25_11 | 12,520 5.33 82.64
    ._27_11 | 344 0.15 82.79
    ._41_11 | 2,281 0.97 83.76
    ._44_11 | 347 0.15 83.91
    ._47_11 | 1,047 0.45 84.35
    ._50_11 | 1,506 0.64 84.99
    ._52_11 | 1,097 0.47 85.46
    ._54_11 | 1,487 0.63 86.09
    ._5_11 | 2,248 0.96 87.05
    ._63_11 | 846 0.36 87.41
    ._66_11 | 519 0.22 87.63
    ._68_11 | 5,031 2.14 89.77
    ._70_11 | 704 0.30 90.07
    ._73_11 | 7,062 3.00 93.07
    ._76_11 | 2,227 0.95 94.02
    ._81_11 | 179 0.08 94.10
    ._85_11 | 309 0.13 94.23
    ._86_11 | 149 0.06 94.29
    ._88_11 | 40 0.02 94.31
    ._8_11 | 1,525 0.65 94.96
    ._91_11 | 90 0.04 95.00
    ._94_11 | 19 0.01 95.00
    ._95_11 | 54 0.02 95.03
    ._97_11 | 23 0.01 95.04
    ._99_11 | 33 0.01 95.05
    1_._11 | 10,440 4.44 99.49
    2_._11 | 144 0.06 99.55
    3_._11 | 173 0.07 99.63
    4_._11 | 109 0.05 99.67
    5_._11 | 66 0.03 99.70
    6_._11 | 705 0.30 100.00
    ------------+-----------------------------------
    Total | 235,103 100.00

    I am trying to label it, but I am getting an error after running this line of code:
    By the way, I am changing the dots in the names of the categries with 0

    label var lugnac_depart "Departamento de Nacimiento"
    label define lugnac_departl 0_5_11 "Antioquia" /*
    */ 0_8_11 "Atlántico" /*
    */ 0_0_11 "Bogotá D.C" /*
    */ 0_13_11 "Bolivar" /*
    */ 0_15_11 "Boyacá" /*
    */ 0_17_11 "Caldas" /*
    */ 0_18_11 "Caquetá" /*
    */ 0_19_11 "Cauca" /*
    */ 0_20_11 "Cesar" /*
    */ 0_23_11 "Córdoba" /*
    */ 0_25_11 "Cundinamarca"/*
    */ 0_27_11 "Choco" /*
    */ 0_41_11 "Huila" /*
    */ 0_44_11 "La Guajira" /*
    */ 0_47_11 "Magdalena" /*
    */ 0_50_11 "Meta" /*
    */ 0_52_11 "Nariño" /*
    */ 0_54_11 "Norte de Santander" /*
    */ 0_63_11 "Quindio" /*
    */ 0_66_11 "Risaralda" /*
    */ 0_68_11 "Santander" /*
    */ 0_70_11 "Sucre" /*
    */ 0_73_11 "Tolima" /*
    */ 0_76_11 "Valle del Cauca" /*
    */ 0_81_11 "Arauca" /*
    */ 0_85_11 "Casanare" /*
    */ 0_86_11 "Putumayo" /*
    */ 0_88_11 "San Andres" /*
    */ 0_91_11"Amazonas" /*
    */ 0_94_11 "Guainia" /*
    */ 0_95_11 "Guaviare" /*
    */ 0_97_11 "Vaupes" /*
    */ 0_99_11 "Vichada" /*
    */ 1_0_11 "Venezuela" /*
    */ 2_0_11 "Estados Unidos" /*
    */ 3_0_11 "Ecuador" /*
    */ 4_0_11 "España" /*
    */ 5_0_11 "Perú" /*
    */ 6_0_11 "Otro"

    label value lugnac_depart lugnac_departl


    The error I am gettin is the error 198: invalid syntax

    Can anyone help me?



  • #2
    /* */ is a way to create a comment block. Unless I'm misunderstanding something, it looks like you want Stata to continue with the same label define command on the next line. You can do this with three forward slashes.

    Code:
    label define lugnac_departl 0_5_11 "Antioquia" ///
    0_8_11 "Atlántico" ///
    0_0_11 "Bogotá D.C" ///
    0_13_11 "Bolivar" ///
    0_15_11 "Boyacá" ///
    etcetera.

    Comment


    • #3
      Well, the syntax is

      Code:
      label define # "label"
      where # is an integer (or extended missing value). Strings such as 0_8_11 are not integers.

      Comment


      • #4
        You can't attach value labels to string variables. You can have a string variable with different information. The best way to do that is often to have a small dataset with a translation table and then merge with your main dataset. Here I imagine that the main dataset is in whatever.dta but naturally you should use the real dataset filename.


        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str17 lugnac_depart str21 lugnac_departl
        "0_5_11"  "Antioquia"         
        "0_8_11"  "Atlántico"        
        "0_0_11"  "Bogotá D.C"       
        "0_13_11" "Bolivar"           
        "0_15_11" "Boyacá"           
        "0_17_11" "Caldas"            
        "0_18_11" "Caquetá"          
        "0_19_11" "Cauca"             
        "0_20_11" "Cesar"             
        "0_23_11" "Córdoba"          
        "0_25_11" "Cundinamarca"      
        "0_27_11" "Choco"             
        "0_41_11" "Huila"             
        "0_44_11" "La Guajira"        
        "0_47_11" "Magdalena"         
        "0_50_11" "Meta"              
        "0_52_11" "Nariño"           
        "0_54_11" "Norte de Santander"
        "0_63_11" "Quindio"           
        "0_66_11" "Risaralda"         
        "0_68_11" "Santander"         
        "0_70_11" "Sucre"             
        "0_73_11" "Tolima"            
        "0_76_11" "Valle del Cauca"   
        "0_81_11" "Arauca"            
        "0_85_11" "Casanare"          
        "0_86_11" "Putumayo"          
        "0_88_11" "San Andres"        
        "0_91_11" "Amazonas"          
        "0_94_11" "Guainia"           
        "0_95_11" "Guaviare"          
        "0_97_11" "Vaupes"            
        "0_99_11" "Vichada"           
        "1_0_11"  "Venezuela"         
        "2_0_11"  "Estados Unidos"    
        "3_0_11"  "Ecuador"           
        "4_0_11"  "España"           
        "5_0_11"  "Perú"             
        "6_0_11"  "Otro"              
        end
        
        merge 1:m lugnac_depart using whatever.dta  
        tab _merge

        Comment


        • #5
          Thank you guys....

          I trid this and it worked

          gen lugnac_departdos= "Bogota" if lugar_nacimiento== 1
          replace lugnac_departdos= "Antioquia" if departamento_nacio== 5
          replace lugnac_departdos= "Atlántico" if departamento_nacio== 8
          replace lugnac_departdos= "Bolivar" if departamento_nacio== 13
          replace lugnac_departdos= "Boyacá" if departamento_nacio== 15
          replace lugnac_departdos= "Caldas" if departamento_nacio== 17
          replace lugnac_departdos= "Caquetá" if departamento_nacio== 18
          replace lugnac_departdos= "Cauca" if departamento_nacio== 19
          replace lugnac_departdos= "Cesar" if departamento_nacio== 20
          replace lugnac_departdos= "Córdoba" if departamento_nacio== 23
          replace lugnac_departdos= "Cundinamarca" if departamento_nacio== 25
          replace lugnac_departdos= "Choco" if departamento_nacio== 27
          replace lugnac_departdos= "Huila" if departamento_nacio== 41
          replace lugnac_departdos= "La Guajira" if departamento_nacio== 44
          replace lugnac_departdos= "Magdalena" if departamento_nacio== 47
          replace lugnac_departdos= "Meta" if departamento_nacio== 50
          replace lugnac_departdos= "Nariño" if departamento_nacio== 52
          replace lugnac_departdos= "Norte de Santander" if departamento_nacio== 54
          replace lugnac_departdos= "Quindio" if departamento_nacio== 63
          replace lugnac_departdos= "Risaralda" if departamento_nacio== 66
          replace lugnac_departdos= "Santander" if departamento_nacio== 68
          replace lugnac_departdos= "Sucre" if departamento_nacio== 70
          replace lugnac_departdos= "Tolima" if departamento_nacio== 73
          replace lugnac_departdos= "Valle del Cauca" if departamento_nacio== 76
          replace lugnac_departdos= "Arauca" if departamento_nacio== 81
          replace lugnac_departdos= "Casanare" if departamento_nacio== 85
          replace lugnac_departdos= "Putumayo" if departamento_nacio== 86
          replace lugnac_departdos= "San Andres" if departamento_nacio== 88
          replace lugnac_departdos= "Amazonas" if departamento_nacio== 91
          replace lugnac_departdos= "Guainia" if departamento_nacio== 94
          replace lugnac_departdos= "Guaviare" if departamento_nacio== 95
          replace lugnac_departdos= "Vaupes" if departamento_nacio== 97
          replace lugnac_departdos= "Vichada" if departamento_nacio== 99
          replace lugnac_departdos= "Venezuela " if pais_nacio== 1
          replace lugnac_departdos= "Estados Unidos " if pais_nacio== 2
          replace lugnac_departdos= "Ecuador" if pais_nacio== 3
          replace lugnac_departdos= "España" if pais_nacio== 4
          replace lugnac_departdos= "Perú" if pais_nacio== 5
          replace lugnac_departdos= "Otro" if pais_nacio== 6

          Comment

          Working...
          X