Announcement

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

  • Problem in generating a variable

    Dear Profs and colleagues,
    I am, going to compute the total number of immigrants based on nacio which shows the nationality of individuals. Since the nacio is a string variable I made a variable immigrant which has a value 1 (immigrants).
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float immigrant str6 nacio
    1 "ES"
    1 "RO"
    1 "UA"
    1 "CV"
    1 "GW"
    1 "UA"
    1 "CV"
    1 "FR"
    1 "BR"
    1 "GW"
    1 "BR"
    1 "BG"
    1 "AO"
    1 "CV"
    1 "BR"
    1 "CV"
    1 "RO"
    1 "GN"
    1 "CV"
    1 "BR"
    1 "CV"
    1 "BR"
    1 "GE"
    1 "CV"
    1 "UA"
    1 "BR"
    1 "UA"
    1 "BR"
    1 "BR"
    1 "GN"
    1 "UA"
    1 "CV"
    1 "MD"
    1 "CV"
    1 "GW"
    1 "GW"
    1 "BR"
    1 "CV"
    1 "DE"
    1 "BR"
    1 "AP"
    1 "MD"
    1 "RO"
    1 "MD"
    1 "CV"
    1 "RO"
    1 "RO"
    1 "ST"
    1 "CN"
    1 "BR"
    1 "RU"
    1 "GW"
    1 "CV"
    1 "CV"
    1 "BR"
    1 "UA"
    1 "AO"
    1 "IN"
    1 "UA"
    1 "MD"
    1 "MD"
    1 "BR"
    1 "ST"
    1 "BR"
    1 "MD"
    1 "RO"
    1 "BR"
    1 "GN"
    1 "BR"
    1 "BR"
    1 "UA"
    1 "UA"
    1 "RO"
    1 "BE"
    1 "UA"
    1 "BR"
    1 "BR"
    1 "CV"
    1 "RO"
    1 "BR"
    1 "BR"
    1 "CV"
    1 "FR"
    1 "BR"
    1 "UA"
    1 "BR"
    1 "AO"
    1 "UA"
    1 "CV"
    1 "BR"
    1 "CV"
    1 "RO"
    1 "BR"
    1 "BR"
    1 "CV"
    1 "GW"
    1 "BR"
    1 "UA"
    1 "BR"
    1 "BR"
    end
    I did this syntax but something is wrong. Because the total number of immigrants is 145,165 while
    num_immi generates very large values, larger than total number of immigrants.
    Code:
    egen num_immi = total(immigrant), by(nacio )
    
    . tab immigrant
    
      immigrant |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |    145,165      100.00      100.00
    ------------+-----------------------------------
          Total |    145,165      100.00
    
    . sum num_immi
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
        num_immi |    145,165    17948.51    16001.13          1      41610
    end
    Any ideas are appreciated. I really have no idea whats wrong here.

    Cheers,
    Paris

  • #2
    Check whether you have more than one variable whose name starts with nacio.

    Code:
    ds nacio*

    Comment


    • #3
      Thank you so much Prof Cox. Always trivial stuff creates huge problems in STATA.

      Comment

      Working...
      X