Announcement

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

  • How to create a codebook of all variables with percentage and cumulative for each value of each variable


    Dear all, I have a question I have been trying to solve the whole day. I need an evaluation of all variables where for each label the frequency, percent and cumulative is given (see table below):
    Value Label Frequency Percent Per(nonm) Cum
    ------------------------------------------------------------------
    1 gotten better 117 6.46% 6.90% 6.46%
    2 stayed the same 472 26.08% 27.83% 32.54%
    3 gotten worse 1107 61.16% 65.27% 93.70% .
    .....

    For now I generate a codebook with only value, labes and frequency but I can't include also percent and cum. Any help will be highly appreciated! Thanks a lot! Filip

  • #2
    Please post a better, more readable example. See FAQ Advice #12.

    Comment


    • #3
      Hi,

      here is the codebook I've generated so far. I need a column with the percentage of each value and a column with cumulative percentage.

      Click image for larger version

Name:	Problem1.jpg
Views:	1
Size:	91.3 KB
ID:	1405651


      Here is how I need it at the end (This is from SAS):

      Click image for larger version

Name:	Problem.jpg
Views:	1
Size:	75.6 KB
ID:	1405653
      Attached Files

      Comment


      • #4
        Probably the -tabulate- command is what you're looking for, although it won't give you cumulative absolute frequencies. See also http://www.stata.com/support/faqs/da...e-frequencies/ (by Nick Cox).

        Code:
        sysuse cancer
        tabulate drug

        Comment


        • #5
          Yes, this is what I am looking for. However, I want to generate such a table for all variables in the dataset at the same time and get something as a codebook.
          Is that possible at all in STATA?

          Comment


          • #6
            I don't know about STATA. Please read the entire FAQ carefully: https://www.statalist.org/forums/help#spelling

            In Stata you could always clone the codebook code and write your own variant.

            You can get some way otherwise with groups (SSC, and also SJ 17(3)) See https://www.statalist.org/forums/for...updated-on-ssc for a recent briefing.

            Here is a token script:

            Code:
            sysuse auto, clear
            
            foreach v of var price-foreign { 
            
                local header `"`: var label `v''"' 
                if `"`header'"' == "" local header "`v'" 
                
                di `"{title:`header'}"' _n
                
                groups `v', show(f p F P) 
                
                di 
            }
            and here are the results in part:

            Code:
            Price
            
            
              +-----------------------------------------+
              |  price   Freq.   Percent   #<=      %<= |
              |-----------------------------------------|
              |  3,291       1      1.35     1     1.35 |
              |  3,299       1      1.35     2     2.70 |
              |  3,667       1      1.35     3     4.05 |
              |  3,748       1      1.35     4     5.41 |
              |  3,798       1      1.35     5     6.76 |
              |-----------------------------------------|
              |  3,799       1      1.35     6     8.11 |
              |  3,829       1      1.35     7     9.46 |
              |  3,895       1      1.35     8    10.81 |
              |  3,955       1      1.35     9    12.16 |
              |  3,984       1      1.35    10    13.51 |
              |-----------------------------------------|
              |  3,995       1      1.35    11    14.86 |
              |  4,010       1      1.35    12    16.22 |
              |  4,060       1      1.35    13    17.57 |
              |  4,082       1      1.35    14    18.92 |
              |  4,099       1      1.35    15    20.27 |
              |-----------------------------------------|
              |  4,172       1      1.35    16    21.62 |
              |  4,181       1      1.35    17    22.97 |
              |  4,187       1      1.35    18    24.32 |
              |  4,195       1      1.35    19    25.68 |
              |  4,296       1      1.35    20    27.03 |
              |-----------------------------------------|
              |  4,389       1      1.35    21    28.38 |
              |  4,424       1      1.35    22    29.73 |
              |  4,425       1      1.35    23    31.08 |
              |  4,453       1      1.35    24    32.43 |
              |  4,482       1      1.35    25    33.78 |
              |-----------------------------------------|
              |  4,499       1      1.35    26    35.14 |
              |  4,504       1      1.35    27    36.49 |
              |  4,516       1      1.35    28    37.84 |
              |  4,589       1      1.35    29    39.19 |
              |  4,647       1      1.35    30    40.54 |
              |-----------------------------------------|
              |  4,697       1      1.35    31    41.89 |
              |  4,723       1      1.35    32    43.24 |
              |  4,733       1      1.35    33    44.59 |
              |  4,749       1      1.35    34    45.95 |
              |  4,816       1      1.35    35    47.30 |
              |-----------------------------------------|
              |  4,890       1      1.35    36    48.65 |
              |  4,934       1      1.35    37    50.00 |
              |  5,079       1      1.35    38    51.35 |
              |  5,104       1      1.35    39    52.70 |
              |  5,172       1      1.35    40    54.05 |
              |-----------------------------------------|
              |  5,189       1      1.35    41    55.41 |
              |  5,222       1      1.35    42    56.76 |
              |  5,379       1      1.35    43    58.11 |
              |  5,397       1      1.35    44    59.46 |
              |  5,705       1      1.35    45    60.81 |
              |-----------------------------------------|
              |  5,719       1      1.35    46    62.16 |
              |  5,788       1      1.35    47    63.51 |
              |  5,798       1      1.35    48    64.86 |
              |  5,799       1      1.35    49    66.22 |
              |  5,886       1      1.35    50    67.57 |
              |-----------------------------------------|
              |  5,899       1      1.35    51    68.92 |
              |  6,165       1      1.35    52    70.27 |
              |  6,229       1      1.35    53    71.62 |
              |  6,295       1      1.35    54    72.97 |
              |  6,303       1      1.35    55    74.32 |
              |-----------------------------------------|
              |  6,342       1      1.35    56    75.68 |
              |  6,486       1      1.35    57    77.03 |
              |  6,850       1      1.35    58    78.38 |
              |  7,140       1      1.35    59    79.73 |
              |  7,827       1      1.35    60    81.08 |
              |-----------------------------------------|
              |  8,129       1      1.35    61    82.43 |
              |  8,814       1      1.35    62    83.78 |
              |  9,690       1      1.35    63    85.14 |
              |  9,735       1      1.35    64    86.49 |
              | 10,371       1      1.35    65    87.84 |
              |-----------------------------------------|
              | 10,372       1      1.35    66    89.19 |
              | 11,385       1      1.35    67    90.54 |
              | 11,497       1      1.35    68    91.89 |
              | 11,995       1      1.35    69    93.24 |
              | 12,990       1      1.35    70    94.59 |
              |-----------------------------------------|
              | 13,466       1      1.35    71    95.95 |
              | 13,594       1      1.35    72    97.30 |
              | 14,500       1      1.35    73    98.65 |
              | 15,906       1      1.35    74   100.00 |
              +-----------------------------------------+
            
            Mileage (mpg)
            
            
              +--------------------------------------+
              | mpg   Freq.   Percent   #<=      %<= |
              |--------------------------------------|
              |  12       2      2.70     2     2.70 |
              |  14       6      8.11     8    10.81 |
              |  15       2      2.70    10    13.51 |
              |  16       4      5.41    14    18.92 |
              |  17       4      5.41    18    24.32 |
              |--------------------------------------|
              |  18       9     12.16    27    36.49 |
              |  19       8     10.81    35    47.30 |
              |  20       3      4.05    38    51.35 |
              |  21       5      6.76    43    58.11 |
              |  22       5      6.76    48    64.86 |
              |--------------------------------------|
              |  23       3      4.05    51    68.92 |
              |  24       4      5.41    55    74.32 |
              |  25       5      6.76    60    81.08 |
              |  26       3      4.05    63    85.14 |
              |  28       3      4.05    66    89.19 |
              |--------------------------------------|
              |  29       1      1.35    67    90.54 |
              |  30       2      2.70    69    93.24 |
              |  31       1      1.35    70    94.59 |
              |  34       1      1.35    71    95.95 |
              |  35       2      2.70    73    98.65 |
              |--------------------------------------|
              |  41       1      1.35    74   100.00 |
              +--------------------------------------+
            
            Repair Record 1978
            
            
              +----------------------------------------+
              | rep78   Freq.   Percent   #<=      %<= |
              |----------------------------------------|
              |     1       2      2.90     2     2.90 |
              |     2       8     11.59    10    14.49 |
              |     3      30     43.48    40    57.97 |
              |     4      18     26.09    58    84.06 |
              |     5      11     15.94    69   100.00 |
              +----------------------------------------+

            Comment


            • #7
              Thanks a lot! Unfortunately Stata 12 (my version) seems to be unable to recognize the groups command

              Comment


              • #8
                As indicated in #4 you must install it first. At this time the SJ version is in press so

                Code:
                ssc install groups
                is the favoured method.


                Using version 12 shouldn't be a problem.

                Comment

                Working...
                X