The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Topics » Reproductive Health » Child marriage median Mozambique (Challenges matching the DHS report)
Child marriage median Mozambique [message #30183] Wed, 09 October 2024 16:10 Go to next message
Simon is currently offline  Simon
Messages: 3
Registered: October 2024
Member
Hi there,

I wrote some stata code to automatically return medians in complex survey design datasets. Compliments this post: https://userforum.dhsprogram.com/index.php?t=msg&th=1337 &goto=2470&S=08c954804736d97c007deae6e959abed#msg_24 70


Here it is:



tempfile outputlog
log using `outputlog', text replace

tab ageMarried if gender1 == 1 & age > 24 & age < 50 [iweight=wt],m

log close

file open myfile using `outputlog', read
file read myfile line

local cum_sum = 0
local prev_cum_pct = 0
local stopper = 0

while r(eof) == 0 {

if `stopper' == 3 {

}
else {
if regexm("`line'", "[0-9]+") {
local cum_pct = real(word("`line'", -1))
local age_pct = real(word("`line'", 1))



if `cum_pct' < 50 | `prev_cum_pct' == 0 {
local prev_cum_pct = `cum_pct'
local prev_cum_pct1 = `cum_pct'
}
else if `cum_pct' >= 50 {
local stopper = `stopper' + 1
local medianCalc = (`age_pct')+1*(50-`prev_cum_pct')/(`cum_pct'-`prev_cum_pct')
display `medianCalc'

}



}


}
file read myfile line
}

file close myfile



You might have to vary the stopper limit depending on the variable - I couldn't find a nicer way of escaping the while...

Cheers
Re: Child marriage median Mozambique [message #30209 is a reply to message #30183] Tue, 15 October 2024 13:58 Go to previous message
Janet-DHS is currently offline  Janet-DHS
Messages: 888
Registered: April 2022
Senior Member
Following is a response from DHS staff member, Tom Pullum:

Thank you for posting this!  I haven't tried it but it's good to have alternative procedures.
Previous Topic: Concerning some variables
Goto Forum:
  


Current Time: Thu Nov 21 18:24:45 Coordinated Universal Time 2024