The DHS Program User Forum
Discussions regarding The DHS Program data and results
 Liz-DHS Messages: 1516Registered: February 2013 Senior Member
Dear User,
Malawi 2010 P49 Table 4.6
I am not a programmer but here is some of the CSPro code for this table "Age at 1st Birth". It may help in figuring things out.

crosstab float(1) T406 v013w+age20t+age25t agebirth+nobirth+nummed
exclude(specval, rowzero, colzero, totals, percents)
{+US}
title( "Table 4.6 Age at first birth"," ",
"Percentage of women age 15-49 who gave birth by exact ages, percentage who",
"have never given birth, and median age at first birth, according",
"to current age, Malawi 2010" )
stub( "Current age" );
{US+}

Note:
The row variables are:
v013w - age - Value labels 1 15-19, 2 20-24, 3 25-29, 4 30-34, 5 35-39, 6 40-44, 7 45-49, 8 50-54, 9 55-59
age20 - age - Women Age - Value labels 1 20-49
age25t Value labels 1 25-49
The column variables are:
agebirth - Percentage who gave birth by exact age - Value labels 1 15, 2 18, 3 20, 4 22, 5 25
nobirth - Percentage who have never given birth - Value labels 1 Percentage who have never given birth
nummed - Value labels - 1 number of women, 2 median age at 1st birth
{ Table 4.6 processing }
jtot = tblcol( t406 ) - 1;
jmax = jtot - 1;
do j = 0 while j <= jmax by 1
t406[*,j] = t406[*,j] * 100 / t406[*,jtot];
if j > 0 & j < jmax then { to have births by exact ages }
t406[*,j] = t406[*,j] + t406[*,j-1]; { it's necessary to accumulate }
endif;
enddo;
t406[0,1:jmax-1] = default; { default row for women 15-19 }
t406[1,3:jmax-1] = default; { default row for women 20-24 }
t406[*,jtot+1] = tblmed( column t406w[*,0:maxage] intervals(highest default) );
itot = tblrow( t406 );
t406[itot-1,3:jmax-1] = default; { default row for women 20-49 }
do i = 0 while i <= itot by 1
maxval = (i+3) * 5;
if i = itot then { women 25-49 }
maxval = 25
elseif i = itot - 1 then { women 20-49 }
maxval = 20
endif;
if t406(i,jtot+1) < 0 | t406(i,jtot+1) >= maxval then
t406(i,jtot+1) = default
endif;
enddo;

{ ------------------------------------------------------------ ------------ }
{ table 4.6 }

box V212 => agebirth;
<15 => 1;
15-17 => 2;
18-19 => 3;
20-21 => 4;
22-24 => 5;
=> notappl;
endbox;
nobirth = ( V201 = 0 );
t = xtab( t406, rweight );
if emsample then
agebirth = notappl;
nobirth = 1;
t = xtab( t406, singwgt*rweight );
endif;
agemed = V212;
if V201 = 0 | agemed > maxage then agemed = maxage endif;
t = xtab( t406w, rweight );
if emsample then
agemed = maxage;
t = xtab( t406w, singwgt*rweight );
endif;

P76, Table 6.3 Age at 1st marriage

crosstab float(1) t603 v013w+age20t+age25t+age20tm+age25tm
colt603+nevmarr+numbmed1 isex
exclude(rowzero,colzero,percents,totals,specval)
{+US}
title( "Table 6.3 Age at first marriage"," ",
"Percentage of women and men age 15-49 who were first married by",
"specific exact ages and median age at first marriage,",
"according to current age, Malawi 2010" )
stub( "Current age" );

Row Variables:
v013w - age - Value labels 1 15-19, 2 20-24, 3 25-29, 4 30-34, 5 35-39, 6 40-44, 7 45-49, 8 50-54, 9 55-59
age20 - age - Women Age - Value labels 1 20-49
age25t Value labels 1 25-49
Age20tm - value label 1 20-54
age25tm - value label 1 25-54
Column Variables:
Colt603
nevmarr value labels 1 Percentage never married
numbmed1 value labels 1 Number, 2 median age at first marriage

Layer variables:
isex value labels 1 Female, 2 Men

{ Table 6.3 processing }
jtot = tblcol( t603 ) - 1;
jmax = jtot - 1;
itot = tblrow( t603 );
do k = 0 while k <= 1 by 1 { for each sex }
do j = 0 while j <= jmax by 1
t603[*,j,k] = t603[*,j,k] * 100 / t603[*,jtot,k];
if j > 0 & j < jmax then { to be married by exact age }
t603[*,j,k] = t603[*,j,k] + t603[*,j-1,k]; { it's necessary to accumulate }
endif;
enddo;
t603[0, 1:jmax-1,k] = default; { default for age 15-19 }
t603[1, 3:jmax-1,k] = default; { default for age 20-24 }
temp = tblrow( t603, age20t );
t603[temp,3:jmax-1,k] = default; { default for age 20-49 }
temp = tblrow( t603, age20tm );
t603[temp,3:jmax-1,k] = default; { default for age 20-49, for men }
t603[*,jtot+1,k] = tblmed( column t603w[*,0:maxage,k] intervals(highest default) );
{ check censoring }
do i = 0 while i <= itot by 1
maxval = (i+3) * 5;
temp = itot - i; { last four rows need special treatment }
if temp in 0,2 then { men 25-59 and men/women 25-49 }
maxval = 25
elseif temp in 1,3 then { men 20-59 and men/women 20-49 }
maxval = 20
endif;
if t603(i,jtot+1,k) < 0 | t603(i,jtot+1,k) >= maxval then
t603(i,jtot+1,k) = default;
endif;
enddo;
enddo;

{ ------------------------------------------------------------ -------- }
{ table 6.3 women}

{ assign notappl to men variables }
age20tm = notappl;
age20m = notappl;
age25tm = notappl;
age25m = notappl;

{ now age for women }
age20t = ( V012 >= 20 );
age20 = age20t;
age25t = ( V012 >= 25 );
age25 = age25t;
age15 = ( V012 in 15:24 );
box V511 => colt603;
<15 => 1;
15-17 => 2;
18-19 => 3;
20-21 => 4;
22-24 => 5;
=> notappl;
endbox;
if V501 = missing then colt603 = notappl endif;
nevmarr = ( V501 = 0 );
t = xtab( t603, rweight );
if emsample then
colt603 = notappl;
nevmarr = 1;
t = xtab( t603, rweight*singwgt );
endif;
agemed = V511;
if V511 = notappl | V511 > maxage then agemed = maxage endif;
t = xtab( t603w, rweight );
if emsample then
xagemed = agemed;
agemed = maxage;
t = xtab( t603w, rweight*singwgt );
agemed = xagemed;
endif;

{ ------------------------------------------------------------ -------- }

{table 6.3 Men}

box MV511 => colt603;
<15 => 1;
15-17 => 2;
18-19 => 3;
20-21 => 4;
22-24 => 5;
=> notappl;
endbox;
if MV501 = missing then colt603 = notappl endif;
nevmarr = ( MV501 = 0 );
t = xtab( t603, rweight );
agemed = MV511;
if MV511 = notappl | MV511 > maxage then agemed = maxage endif;
t = xtab( t603w, rweight )

[Updated on: Thu, 17 April 2014 14:28]

Report message to a moderator