Announcement

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

  • Egen-- total (), type mismatch

    Hi

    I am going to determine how many "nacio" exist in "Expgroup & Edugroup". I used egen--total() though it says: type mismatch

    Any ideas appreacted.

    Cheers,
    Paris

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str2 nacio float(Expgroup Edugroup)
    "PT" 1 1
    "PT" 3 4
    "UA" 1 3
    "PT" 4 4
    "PT" 1 1
    "RO" 1 3
    "PT" 8 2
    "PT" 1 2
    "PT" 1 2
    "PT" 3 2
    "PT" 1 4
    "PT" 1 2
    "PT" 3 2
    "PT" 1 2
    "PT" 1 2
    "PT" 4 3
    end
    
    egen n_nacio = total(nacio), by(Expgroup Edugroup) 
    type mismatch

  • #2
    not sure what you're going to use this for, but here is one way:
    Code:
    egen n_nacio=count(nacio), by(Exp Edu)
    note that this gives a count for each combination of the other 2 variables as I'm guessing that's what you want - if no, please clarify

    Comment


    • #3
      Thank you Rich for getting back to me.
      Its right. I need to know i.e in Exp 1 and Edu 2 how many nacio exist.

      Comment


      • #4
        Is this what you want?

        .
        Code:
         egen tag = tag(nacio Exp Edu)
        
        . egen ndistinct = total(tag), by(Exp Edu)
        
        . tabdisp Exp Edu, c(ndistinct)
        
        ----------------------------------
                  |        Edugroup       
         Expgroup |    1     2     3     4
        ----------+-----------------------
                1 |    1     1     2     1
                3 |          1           1
                4 |                1     1
                8 |          1            
        ----------------------------------

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Is this what you want?
          Not really. There are 1,074,848 in nacio. I guess these numbers of below table does not indicate the purpose.

          Code:
          . egen tag = tag(nacio Exp Edu)
          
          . egen ndistinct = total(tag), by(Exp Edu)
          
          . tabdisp Exp Edu, c(ndistinct)
          
          ----------------------------------
                    |        Edugroup       
           Expgroup |    1     2     3     4
          ----------+-----------------------
                  1 |   31    61    63    54
                  2 |   39    80    70    71
                  3 |   54    85    89    78
                  4 |   61    94    82    57
                  5 |   61    84    73    62
                  6 |   60    84    72    54
                  7 |   60    68    53    42
                  8 |   51    51    42    33
          ---------------------------------
          I assume the code #2 is right.

          Comment

          Working...
          X