Hello,
I would like to know how to add up values in a for loop. I am using DHS data, and using the code below, I would like to add up the total number of siblings that have died in the dataset. The variable mm2_1 is the firstborn (oldest) sibling a respondent has, and a value of '0' means they have died'
forvalues i = 1/20 {
count if mm2_`i'== 0
}
This code returns the following. The first line therefore represents the total number of 'oldest' siblings that have died:
19,958
16,830
14,516
12,341
10,606
8,672
6,719
5,182
3,461
2,110
1,308
616
262
143
59
22
20
6
2
0
All I want is a way to add these numbers up quickly, but I haven't been able to figure out the code.
Thank you!
Kathleen
Related Posts with How to add values in a forvalues loop
Hte package - I cannot perform the command with a poisson distributionHello I'm using the hte package, more specifically the hte sm function, in order to obtain a multil…
new table command cannot parse bracket within string variableIs this the correct place to report an apparent error in parsing? this is Stata/SE 17.0 for Windows …
New version of ipwbreg on SSCThanks yet again to Kit Baum, a new version of the ipwbreg package is now available for download fro…
Calculate how many words separated by a comma match between two string variables gameid year credits1 credits2 1 1996 Aleksandr Kravchuk,Alexey Menshikov,Alexey Menshikov,Rosti…
Searching packages stored at SSC but returns nothingDear Stata users, I find an annoying problem recently. I search packages and Stata returns nothing,…
Subscribe to:
Post Comments (Atom)
0 Response to How to add values in a forvalues loop
Post a Comment