Hello Statalist,

I consider myself a beginner, so I would appreciate your help, and thank you for this learning opportunity.

out of 800 observations, I am interested to tabulate 3 variables:

1- "biz" : which is patient id
2- "status" : which is categorical with two level= surgery and not-surgery
3- "quality" : which is categorical with two level= fail and pass

I am interested to create a new variable (let's call it percent), which has the percentage of "pass" for each biz & status.

So far I use these two commands separately, but they are not giving me what I am interested in:

. by biz status, sort: tab quality

. forvalues i=1/40 {
asdoc tab2 status qm_1 if biz==`i', append col nof save(asa)
}

They show the tabulation tables with percent fail&pass, but I don't know how to transform the percent pass as a new variable to my data set.
Again, I appreciate your help.

Best,
Mahmoud