Announcement

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

  • Too many values error when trying using tabulate command

    Hi
    I am trying to create a table showing the distribution of age of first marriage across many different ethnic groups (i.e. to see where the most common ages are for each ethnicity) but am getting "too many values" when I try to run my code (I have around 200 different ethnic groups). This originally worked when I ran the code by each country when I had separate ethnicity variables for each country, but now I have had to combine them into 1 ethnicity variable and compare them this way.

    My code I am trying to use is as follows:
    Code:
    tab agefrstmar ethnicityall if yrgroup == 0, column nofreq
    The only way I have figured out how I could get the results I wanted was for each ethnic group to do as follows, but this could be quite long so was wondering if there's a shortcut before I do this:
    Code:
    tab agefrstmar ethnicityall if yrgroup == 0 & ethnicity == "Acholi"
    etc

    I tried using a foreach command but this also said there were too many values
    Code:
    foreach ethnicity in ethnicityall { 
        tab agefrstmar `ethnicity' if yrgroup == 0 
    }

  • #2
    Without example data, it's difficult to provide an answer that's suitable to the unseen data. In particular, I cannot be sure if ethnicityall is a string variable with values like "Acholi", or if it's a numeric variable with labelled values. Assuming it's a string variable, perhaps something like the following will start you in a useful direction.
    Code:
    levelsof ethnicityall, local(eth)
    foreach ethnicity of local eth { 
        tab agefrstmar ethnicityall if yrgroup == 0 & ethnicityall==`"`ethnicity'"'
    }

    Comment


    • #3
      To add to @William Lisowski's suggestion: I guess you're hoping that

      Code:
      foreach ethnicity in ethnicityall
      is somehow a loop over the distinct values of ethnicityall, but that's not what it is. It is a loop over a single item so that
      Code:
      foreach ethnicity in ethnicityall {        
           tab agefrstmar `ethnicity' if yrgroup == 0 & ethnicityall == "`ethnicity'"  
      }
      is just a way to say
      Code:
      tab agefrstmar ethnicityall if yrgroup == 0 & ethnicityall == "ethnicityall"
      which is not what you intend.
      Last edited by Nick Cox; 04 Apr 2022, 19:45.

      Comment


      • #4
        Thank you, my ethnicityall variable was a numeric variable but I had made it by encoding a string ethnicity variable. I tried the code William suggested and this worked well. I was just wondering if there was a way to get them all to go in the same table so its easier for me to look at. Here is my data (where ethnicity is a string variable - let me know if you need the numeric version)
        Code:
        clear
        input byte agefrstmar str27 ethnicity
        12 "Peulh"        
        11 "Bariba"       
        14 "Bariba"       
        17 "Bariba"       
        12 "Bariba"       
        10 "Bariba"       
        11 "Bariba"       
        14 "Peulh"        
        17 "Peulh"        
        24 "Peulh"        
        16 "Peulh"        
        19 "Peulh"        
        32 "Peulh"        
        13 "Peulh"        
        11 "Bariba"       
        12 "Bariba"       
        16 "Bariba"       
        16 "Bariba"       
        15 "Bariba"       
        12 "Bariba"       
        12 "Bariba"       
        23 "Peulh"        
        12 "Peulh"        
        11 "Bariba"       
        15 "Bariba"       
        15 "Bariba"       
        16 "Peulh"        
        11 "Bariba"       
        14 "Bariba"       
        19 "Bariba"       
        37 "Bariba"       
        15 "Bariba"       
        13 "Bariba"       
        21 "Peulh"        
        16 "Bariba"       
        16 "Bariba"       
        17 "Bariba"       
        26 "Yoruba"       
        13 "Bariba"       
        10 "Bariba"       
        15 "Bariba"       
        16 "Bariba"       
        10 "Bariba"       
        19 "Bariba"       
        15 "Bariba"       
        18 "Bariba"       
        26 "Bariba"       
        19 "Bariba"       
        20 "Bariba"       
        17 "Bariba"       
        14 "Bariba"       
        20 "Bariba"       
        16 "Bariba"       
        20 "Bariba"       
        15 "Bariba"       
        12 "Bariba"       
        11 "Bariba"       
        13 "Peulh"        
        15 "Bariba"       
        14 "Bariba"       
        12 "Bariba"       
        15 "Dendi"        
        15 "Bariba"       
        14 "Dendi"        
        16 "Dendi"        
        21 "Bariba"       
        14 "Bariba"       
        20 "Bariba"       
        13 "Bariba"       
        21 "Yoruba"       
        19 "Bariba"       
        12 "Bariba"       
        36 "Bariba"       
        12 "Bariba"       
        21 "Fon"          
        18 "Yoa and Lokpa"
        24 "Bariba"       
        19 "Bariba"       
        18 "Peulh"        
        17 "Peulh"        
        20 "Dendi"        
        14 "Fon"          
        12 "Bariba"       
        19 "Bariba"       
        22 "Bariba"       
        14 "Bariba"       
        19 "Bariba"       
        14 "Bariba"       
        15 "Bariba"       
        29 "Yoruba"       
        17 "Peulh"        
        18 "Bariba"       
        20 "Bariba"       
        25 "Bariba"       
        17 "Bariba"       
        19 "Bariba"       
        18 "Bariba"       
        16 "Bariba"       
        27 "Bariba"       
        16 "Bariba"       
        end
        label values agefrstmar agefrstmar_lbl

        Comment


        • #5
          This is what
          Code:
          help limits
          tells me in Stata 17


          Code:
          tabulate                                           Stata/BE Stata/SE and MP
          # of rows in one-way table                          3,000                12,000
          # of rows & cols in two-way table                  300x20              1,200x80
          My guess is that the 20 columns limit is biting you, but your table would probably not be readable any way.

          Run

          Code:
          tab agefrstmar 
          di r(r) 
          tab ethnicity 
          di r(r)
          and tell us the number of rows reported.

          Comment


          • #6
            For agefrstmar I have 59 rows and for ethnicity I have 221 rows

            Comment


            • #7
              If you could get that table how would you read it?

              Comment


              • #8
                Do you mean the original table I am trying to get? I want to create treatment and control groups by ethnicity - so ethnic groups with the most common proportions of marriage occurring under 18 would be my treatment group and the rest would be my control.

                E.g. when I intially did it for each country separately (where each country had their own ethnicity variable) this is what I got - I want to try and get this but for all ethnicities as some ethnic groups crossover into multiple countries so my original way isn't suitable.

                Code:
                    Age at |
                     first |
                  marriage |
                        or |
                cohabitati |
                        on |
                (calculate |                Ethnicity, Cote d'Ivoire
                        d) |      Akan       Krou  Mand, nor  Mand, sou     Voltac |     Total
                -----------+-------------------------------------------------------+----------
                        10 |      1.00       0.97       0.56       0.00       1.09 |      0.80 
                        11 |      2.66       1.94       1.12       2.91       2.72 |      2.30 
                        12 |      6.31       2.91       3.91       4.85       3.80 |      4.71 
                        13 |      8.31       5.83       8.38       5.83       9.24 |      7.93 
                        14 |      9.63       8.74      17.88      16.50      14.67 |     13.10 
                        15 |     15.28      12.62      16.76      16.50      17.39 |     15.86 
                        16 |     12.29      18.45      15.64      11.65      16.85 |     14.60 
                        17 |     10.30      25.24      12.85      10.68      14.13 |     13.45 
                        18 |     10.96       6.80       8.38       9.71       7.07 |      8.97 
                        19 |      6.64       7.77       5.59       5.83       5.43 |      6.21 
                        20 |      6.31       3.88       2.23       6.80       2.72 |      4.48 
                        21 |      2.33       0.97       1.68       2.91       0.00 |      1.61 
                        22 |      1.00       0.97       0.56       0.97       0.54 |      0.80 
                        23 |      1.99       0.97       2.23       0.00       0.54 |      1.38 
                        24 |      1.99       0.97       0.00       1.94       1.09 |      1.26 
                        25 |      1.33       0.97       0.00       0.97       1.09 |      0.92 
                        26 |      0.66       0.00       1.68       0.97       0.54 |      0.80 
                        27 |      0.33       0.00       0.00       0.00       0.00 |      0.11 
                        28 |      0.33       0.00       0.00       0.00       1.09 |      0.34 
                        29 |      0.33       0.00       0.56       0.00       0.00 |      0.23 
                        33 |      0.00       0.00       0.00       0.97       0.00 |      0.11 
                -----------+-------------------------------------------------------+----------
                     Total |    100.00     100.00     100.00     100.00     100.00 |    100.00

                Comment

                Working...
                X