Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: Generate a variable using Freq. of one variable and Percent of another variable‏

 From Jonathan Grondin To statalist2 Subject st: Generate a variable using Freq. of one variable and Percent of another variable‏ Date Wed, 20 Jul 2011 20:03:32 +0000

```Stata/MP 10.1 for Windows
Born 10 Jun 2010

Hi there,

I have conducted a questionnaire and every question can be answered by a value of 1 through 10. I have two groups who have taken the questionnaire, group "a" and group "b" and I have divided every question into 2 variables.
Question four would be divided this way: "q4a" and "q4b".
For every student and every question, I wish to compare the proportion of student from one group who provided the same answer as the students in the other group.
For example: Sam, a student in group "a", has answered "6" to question four. In group "b", out of ten students, three student have answered "6" to the same question. Thus, Sam's proportion for question four would be "3/10".

Now, I want to generate a variable that would hold these proportions as values.

Here is a tabulate of the two groups on question four to explain better my need. Following, I have provided an example of the variable I would like to generate.

. tab  q4a

q4a |      Freq.     Percent        Cum.
------------+-----------------------------------
1 |         12        2.78        2.78
2 |         72       16.71       19.49
3 |        109       25.29       44.78
4 |        122       28.31       73.09
5 |         67       15.55       88.63
6 |         26        6.03       94.66
7 |          9        2.09       96.75
8 |          8        1.86       98.61
9 |          4        0.93       99.54
10 |          2        0.46      100.00
------------+-----------------------------------
Total |        431      100.00

. tab  q4b

q4b |      Freq.     Percent        Cum.
------------+-----------------------------------
2 |          2        0.78        0.78
4 |          7        2.72        3.50
5 |         18        7.00       10.51
6 |         25        9.73       20.23
7 |         31       12.06       32.30
8 |         37       14.40       46.69
9 |         48       18.68       65.37
10 |         89       34.63      100.00
------------+-----------------------------------
Total |        257      100.00

I would like to get a variable like this

. tab  q4a

q4a |      Freq.     Percent        Cum.
------------+-----------------------------------
0 |         12        2.78        2.78
2/257 |         72       16.71       19.49
0 |        109       25.29       44.78
7/257 |        122       28.31       73.09
18/257 |         67       15.55       88.63
25/257 |         26        6.03       94.66
31/257 |          9        2.09       96.75
37/257 |          8        1.86       98.61
48/257 |          4        0.93       99.54
89/257 |          2        0.46      100.00
------------+-----------------------------------
Total |        431      100.00

Any suggestions ?

Thank you so much

Jonathan
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```