Lucas
Lucas

Reputation: 1480

How to create a pivot table using row values as columns?

I have a dataset with individual information on education, occupation, race and wage (Here is the data). I would like to create a table group by educational and occupational group, where the columns will be one of each possible race.

I know collapse, and I'm able to create, for example, mean wage by each subgroup using:

collapse (mean) wage, by(educ ocup)

However, I cannot figure out how to transform the row observation in columns. After encoding race, I tried:

collapse (count) race , by(educ ocup)

But it didn't work as expected.

My desired output is:

                               black  hispanic  white
educ          ocup                                  
Phd           public sector     0.0       1.0    0.0
college       private sector    1.0       0.0    0.0
              public sector     0.0       0.0    3.0
high school   private sector   14.0       7.0   13.0
              public sector    16.0      17.0   17.0
master        private sector    1.0       0.0    0.0
              public sector     0.0       1.0    0.0
middle school private sector   10.0      10.0    9.0
              public sector    16.0      19.0   20.0
some college  private sector    2.0       3.0    3.0
              public sector     8.0       5.0    4.0

Upvotes: 1

Views: 312

Answers (1)

Wouter
Wouter

Reputation: 3271

table ocup race, by(educ) c(count wage)

Upvotes: 2

Related Questions