Understanding Society User Support: Issueshttps://iserredex.essex.ac.uk/support/https://iserredex.essex.ac.uk/support/support/favicon.ico?15995719382016-03-21T11:48:44ZUnderstanding Society User Support
Redmine Understanding Society User Support - Support #535 (Closed): Creating duration of marriage variablehttps://iserredex.essex.ac.uk/support/issues/5352016-03-21T11:48:44ZHarini Annadanam
<p>I am trying to create a variable denoting duration of current marriage (years). The only wave with information on year of marriage is wave b. I am therefore attempting to create a variable with years of marriage which, in each year, gives the current year - year of marriage, provided that the individual is still married. I also want to include years married for individuals who are not married at the start of the bhps sampling, but marry between 1991-2008.</p>
<p>I have attempted to do this with the following Stata codes:<br /><strong>use variables lmary (from wave b - bmarriag), mastat and mlchy4 (from indresp files waves a-r and c-r)</strong></p>
<p>by pid (wave), sort: replace lmary = lmary[_n-1] if lmary >= .<br />by pid (wave), sort: replace lmary = lmary[_n+1] if lmary >= .<br />by pid (wave), sort: replace mlchy4 = mlchy4[_n-1] if mlchy4 >= .</p>
<p><strong>create variable that will give years married when 2-digit year of marriage (lmary) is subtracted from it</strong><br />gen yy1900 = year - 1900<br /><strong>drop if individual was married before 1991 but is not married at the start of the bhps (1991)</strong><br />drop if lmary<1991&lmary!=.&mastat!=1&wave==1<br /><strong>create years married variable for those who became married over the sample</strong><br />gen yearsmarried = (year - mlchy4) if mastat==1<br /><strong>recode missing years married observations for those who were married before the sample, provided they are still married</strong><br />if mastat==1 recode yearsmarried .=(yy1900-lmary)</p>
<p>However, Stata reports error: invalid name</p>
<p>Could someone please let me know what I am doing wrong and if there is a better/simpler way for me to create this variable? Thank you.</p>