Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: RE: RE: Identifying the nearest observation in a household survey


From   "Richard Palmer-Jones" <r.palmer-jones@uea.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: RE: Identifying the nearest observation in a household survey
Date   Fri, 22 Apr 2005 02:10:30 +0100

What I had in mind was to put the serial number of the parent on the child's
record - useful for subsequent linking. My apologies for the sloppiness
first time around - I keep forgetting the indexing in Stata. 
This may be a very cumbersome way of doing things, but it does what I
sometimes want in complex extended families, subject to difficulties in
identifying likely parents - so health warning still applies. 
In some cases I think you have to identify (teenage) parents manually. 
What is odd to me here is the simple coding of relation to Head. For
example, one might want to classify older residents as children of resident
parents. I would think most coding schemes would have codes for son,
daughter ... Anyway, for what its worth, the following works.
Richard

gen byte pernum = 0
gen byte parent = 0
gen long perno = .
gen long parent_of_child = .
gen child = age < 18
qui des
forval i = 1/`r(N)' {
	if related[`i'] == "Head" {
		replace pernum = 1 in `i'
	}
	else {
		replace pernum = pernum[`i'-1] + 1 in `i'
	}
	replace perno = serial[`i'] * 100 + pernum[`i'] in `i'
	if child[`i'] == 1 {
		local j = 1
		local parent = 0
		while `parent' < 1 {
			if age[`i' - `j'] > 18 {
				local i1 = `i' -`j'
				replace parent = 1 in `i1'
				replace parent_of_child = serial[`i'-`j'] *
100 + pernum[`i'-`j'] in `i'
				local parent = 1
			}
			local ++j
		}
	}
}
	
+---------------------------------------------------------------------------
------------+
	serial   rel~d   age   sex   marital   per~m   par~t       perno
parent_~d   child 
	
----------------------------------------------------------------------------
-----------
1.	2411276    Head    88     F     widow       1       0   241127601
.       0 
2.	2411276   Other    49     M    single       2       0   241127602
.       0 
3.	2411276   Other    49     M   married       3       0   241127603
.       0 
4.	2411276   Other    42     F   married       4       1   241127604
.       0 
5.	2411276   Other     6     F    single       5       0   241127605
241127604       1 
	
----------------------------------------------------------------------------
-----------
6.	2411276   Other    68     F     widow       6       0   241127606
.       0 
7.	2411276   Other    58     M     widow       7       0   241127607
.       0 
8.	1    Head    88     F     widow       1       0         101
.       0 
9.	1   Other    49     M    single       2       0         102
.       0 
10.	1   Other    49     M   married       3       0         103
.       0 
	
----------------------------------------------------------------------------
-----------
11.	1   Other    42     F   married       4       1         104
.       0 
12.	1   Other     6     F    single       5       0         105
104       1 
13.	1   Other     5     F    single       6       0         106
104       1 
14.	1   Other     4     F    single       7       0         107
104       1 
15.	1   Other    58     M     widow       8       0         108
.       0 
	
----------------------------------------------------------------------------
-----------
16.	1   Other    20     F    single       9       1         109
.       0 
17.	1   Other     1     F    single      10       0         110
109       1


|-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Scott Merryman
Sent: Thursday, April 21, 2005 8:41 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: RE: Identifying the nearest observation in a household
survey

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of Richard Palmer-Jones
> Sent: Thursday, April 21, 2005 11:44 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: RE: Identifying the nearest observation in a household
> survey
> 
> This won't work if you have more than one child per previous parent.

I am not sure I understand; the parent is flagged only if the age >= 18, it
has the same serial # (thanks Nick), and the following observation is a
flagged a child.

Suppose we have two households:

. l , ab(32) noobs sepby(ser)

  +-----------------------------------------+
  |  serial   related   age   sex   marital |
  |-----------------------------------------|
  | 2411276      Head    88     F     widow |
  | 2411276     Other    49     M    single |
  | 2411276     Other    49     M   married |
  | 2411276     Other    42     F   married |
  | 2411276     Other     6     F    single |
  | 2411276     Other    68     F     widow |
  | 2411276     Other    58     M     widow |
  |-----------------------------------------|
  |       1      Head    88     F     widow |
  |       1     Other    49     M    single |
  |       1     Other    49     M   married |
  |       1     Other    42     F   married |
  |       1     Other     6     F    single |
  |       1     Other     5     F    single |
  |       1     Other     4     F    single |
  |       1     Other    58     M     widow |
  |       1     Other    20     F    single |
  |       1     Other     1     F    single |
  +-----------------------------------------+

. mark child if age <18

. mark parent_of_child if age>=18 & child[_n+1] == 1 & serial ==
serial[_n+1]

. l , ab(32) noobs sepby(ser)

  +-------------------------------------------------------------------+
  |  serial   related   age   sex   marital   child   parent_of_child |
  |-------------------------------------------------------------------|
  | 2411276      Head    88     F     widow       0                 0 |
  | 2411276     Other    49     M    single       0                 0 |
  | 2411276     Other    49     M   married       0                 0 |
  | 2411276     Other    42     F   married       0                 1 |
  | 2411276     Other     6     F    single       1                 0 |
  | 2411276     Other    68     F     widow       0                 0 |
  | 2411276     Other    58     M     widow       0                 0 |
  |-------------------------------------------------------------------|
  |       1      Head    88     F     widow       0                 0 |
  |       1     Other    49     M    single       0                 0 |
  |       1     Other    49     M   married       0                 0 |
  |       1     Other    42     F   married       0                 1 |
  |       1     Other     6     F    single       1                 0 |
  |       1     Other     5     F    single       1                 0 |
  |       1     Other     4     F    single       1                 0 |
  |       1     Other    58     M     widow       0                 0 |
  |       1     Other    20     F    single       0                 1 |
  |       1     Other     1     F    single       1                 0 |
  +-------------------------------------------------------------------+


Scott


> You can identify children, then loop back observation by observation till
> you get to a likely parent - though identifying them may be difficult and
> unclear (guardians) - and watch out for child headed households? With a
> health warning:
> gen parent = .
> gen child if age < 18
> qui des
> foreach i in 1/r(N) {
> 	if child == 1 {
> 		local j = 1
> 		local parent = 0
> 		while `parent' < 1 {
> 			if age[`i' - `j'] = [condition for parent - your
> business]
> 				parent[`i'] = serial[`i'-`j'] * 100 +
> pernum[`i'-`j']
> 				local parent = 1
> 			}
> 			local ++j
> 		}
> 	}
> }


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index