The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Topics » Child Health » How to generate Month-Year birth Cohort (Generating new variables )
How to generate Month-Year birth Cohort [message #29248] Tue, 14 May 2024 20:48 Go to previous message
Atazonomics is currently offline  Atazonomics
Messages: 4
Registered: April 2024
Member
I working on research and I need to group children into month-year cohorts from the IR files of Uganda, Ivory Coast and Nigeria. In the survey rounds 6 or lower, I use the moth of birth and year of birth and use group (b1 b2)and for 7 or 8 wave, i used the following :

* Loop through each child's month and year of birth variables
foreach i of numlist 1/20 {
* Check existence of the month variable
capture confirm variable b1_`i'
if _rc != 0 {
display "Month variable b1_`i' not found. Skipping to next."
continue
}

* Check existence of the year variable
capture confirm variable b2_`i'
if _rc != 0 {
display "Year variable b2_`i' not found. Skipping to next."
continue
}

* Only proceed if both variables are present and not missing
if !missing(b1_`i', b2_`i') {
* Convert month and year to strings with proper formatting
local str_month_`i' = string(b1_`i', "%02.0f")
local str_year_`i' = string(b2_`i')

* Concatenate year and month into a cohort variable
gen cohort_`i' = str_year_`i' + "-" + str_month_`i'
} else {
* Explicitly set cohort to missing if either month or year is missing
gen cohort_`i' = "."
}
}

Both methods did not work .

Please, i look forward to your help as this is holding me up

Thank you
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: still birth
Next Topic: Early childhood development
Goto Forum:
  


Current Time: Tue Nov 26 20:19:59 Coordinated Universal Time 2024