The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Topics » Reproductive Health » Event file
Event file [message #28047] Mon, 06 November 2023 07:32 Go to previous message
md2022 is currently offline  md2022
Messages: 7
Registered: October 2023
Member
Hello,

I am trying to create event files using the DHS calendar data and I am having issues in the code provided in the DHS contraceptive calendar tutorial. Specifically, in example 7 step 7.1. The code is:

. * Step 7.1
. * set length of calendar in a local macro
. local vcal_len = strlen(vcal_`col1'[1])

. * set episode number - initialized to 0
. gen eps = 0

. * set previous calendar column 1 variable to anything that won't be in the calendar
. gen prev_vcal1 = "_"

. * create separate variables for each month of the calendar
. forvalues j = `vcal_len'(-1)1 {
2. local i = `vcal_len' - `j' + 1
3. * contraceptive method, non-use, or birth, pregnancy, or termination
. gen vcal1_`i' = substr(vcal_`col1',`j',1)
4. * reason for discontinuation
. gen vcal2_`i' = substr(vcal_`col2',`j',1)
5.
. * check if we have marriage info
. if "`marr_col'"!="" { // we have a marriage column
6. gen vcal3_`i' = substr(vcal_`col3',`j',1)
7. * set up parameter to add into reshape below, and collapse further below
. local vcal3_ vcal3_
8. local ev906 ev906a=vcal3_
9. }
10. * increase the episode number if there is a change in vcal_1
. replace eps = eps+1 if vcal1_`i' != prev_vcal1
11. * set the episode number
. gen int ev004`i' = eps
12. * save the vcal1 value for the next time through the loop
. replace prev_vcal1 = vcal1_`i'
13. }

When I run this, even with the example data, it returns an error message for local vcal_len = strlen(vcal_`col'[1]) that 'vcal_ ambiguous abbreviation) r(111). When I change it to local vcal_len = strlen(vcal1_`col'[1]) it runs but then it tells me there is an invalid syntax error (r198) with the loop. I am not sure what I am doing wrong but it has not converted the string to separate month by month variables.

Thank you!
 
Read Message
Read Message
Previous Topic: Kenya 2022 calendar data
Next Topic: Weighting
Goto Forum:
  


Current Time: Thu Nov 28 11:02:32 Coordinated Universal Time 2024