[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
Your HHead variable evaluates as 1 or 0.
If you follow that through,
will always be missing. HHead 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
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.
> 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
> 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: