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
test of multicollinarity in multiple linear regression.Hi guys I have a multiple linear regression looking like this : Y = Var1 (dummy) + Var 2 + Var 3 + …
Reshape wide to long variable not foundI have been trying to reshape my data from wide to long This is an example of how it looks like: I…
Question about syntax optionsI am trying to write a program but am having difficulty with the syntax function Code: program de…
Drop duplicate pairs (X,Y; Y,X)Unfortunately, I was not able to find out how to drop a pair of duplicates. Let's say we have variab…
Mixed model syntax and output questionHello -- I am trying to fit a mixed effect linear model to some data. For context, I have 4 raters …
Subscribe to:
Post Comments (Atom)
0 Response to operating sums of columns
Post a Comment