I guess this is about using stata as a very basic calculator--but I really need it to go that way.
I have four variables, ses1-ses4, each records the number of participants who participated in 1,2,3,4 times of sessions (i.e. 14 in ses4 means there are 14 participants who participated in all four sessions)
What I want, then, is the percentage of participants who participated in more than 1 session. I want to use the total percentage of participants participating in multiple sessions as a baseline for my analysis of other things.
I would like to simply sum up all numbers in the columns ses2, ses3 and ses4, and divide that number by the sum of ses1-ses4.
Of course, total(ses1 + ses2) will not work. adding up total(ses1) + total(ses2) won't work either.
I tried to create a new variable, like
gen mult = ses2 + ses3 + ses4
gen total = ses1 + ses2 + ses3 + ses4
then,
total(mult)
total(tot)
but how can I get this perentage? the display function won't work as a calculator:
display "Percentage = " total(mult) / total(tot)
I used a super weird way below to get what I want, but this is so ugly that I really wonder if there is a much more straight forward way to do it. There should be, this is just elementary-level math.
sum ses2
local numerator = r(sum)
sum ses3
local numerator = `numerator' + r(sum)
sum ses4
local numerator = `numerator' + r(sum)
sum ses1
local denominator = r(sum)
sum ses2
local denominator = `denominator' + r(sum)
sum ses3
local denominator = `denominator' + r(sum)
sum ses4
local denominator = `denominator' + r(sum)
display "Percentage = " %3.2f =100*`numerator'/`denominator'
Related Posts with operating sums of columns
Background Color Twoway ChartDear all, I am trying to change the background colour of a twoway chart but it is not working, I ha…
Mediation Analysis with Binary Outcome: Adding Survey WeightsI am using paramed in Stata 15.1 to do mediation with a continuous mediator and a binary outcome. I …
can i use mi chained logistic and how to weight respondentsi have combined survey data sets from 32 countries and have about 90k respondents, the number of res…
Omitted main independent problem in difference-in-differences approach.Hello, I am applying the 2013 shock dated difference-in-differences method for the model covering a …
Direction of bias?Dear all, I am trying to determine directions of biased (upward or downward) estimates in my study …
Subscribe to:
Post Comments (Atom)
0 Response to operating sums of columns
Post a Comment