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

st: RE: Using explicit subscripts to assign a member's value(s) to others in unit


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Using explicit subscripts to assign a member's value(s) to others in unit
Date   Mon, 27 Jun 2005 21:55:39 +0100

Your HHead variable evaluates as 1 or 0. 
If you follow that through, 

HHead[0] 

will always be missing. HHead[1] will, 
under -by serial:- be the first observation
for each distinct value of -serial-. 

replace famunt2=famunit[HHhead] if related=1114

is illegal because you didn't use == to test 
for equality. 

I think you need something more like this: 

gen byte HHhead = related == 101

bysort serial (HHhead): 
	gen famunt2 = famunit[_N] if HHhead[_N] & related == 1114 

This code assumes at most one person who is 101 in 
each household, itself testable. 

Nick 
[email protected] 

Deb Garvey
 
> I'm using 2000 Census data for individuals, with
> family and household information appended to each
> individual record.  I'm running Stata/SE 8.2.
> 
> I am attempting to use Nick Cox's method of assigning
> a source household member's value of a variable to
> others in a household using an explicit subscript to
> refer to the source person (see "st: RE: Creating a
> new variable using household level data" dated 13 Feb 
> 2005 at
> http://www.stata.com/statalist/archive/2005-02/msg00387.html).
> 
> In my case, I wish to assign "famunit" of the
> household head (related=101) to the head's unmarried
> partner (related=1114).  I couldn't figure out how to
> refer to the HH head's observation directly in an
> explicit subscript, so I created an indicator 
> variable "HHhead" for the person's status as HH head:
>  
> . gen byte HHhead=(related==101)
> 
> . gen byte famunt2=famunit
> 
> . by serial: replace famunt2=famunit[HHhead]
> (103 real changes made, 103 to missing)
> 
> I only want to change the value of famunit for
> unrelated partners, but the statement -replace
> famunt2=famunit[HHhead] if related=1114- yields
> "invalid syntax r(198);"
> 
> What am I doing wrong?  I know at least one problem is
> my improper use of the explicit subscript, but I can't
> see my mistake.  
> Incorrect output is below.
 

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index