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

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


From   Deb Garvey <dlgarvey@pacbell.net>
To   statalist@hsph.harvard.edu
Subject   st: Using explicit subscripts to assign a member's value(s) to others in unit
Date   Mon, 27 Jun 2005 13:33:15 -0700 (PDT)

Greetings, all.

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.

Thanks for your help,

Deb Garvey

.l serial pernum related HHhead famu*, nol

+---------------------------------------------------------+
> serial   pernum   related   HHhead   famunit  
> famunt2 
>
---------------------------------------------------------
> 1.  2408215        1       101        1         1   
>      1 
> 2.  2408215        2       201        0         1   
>      . 
> 3.  2408216        1       101        1         1   
>      1 
> 4.  2408216        2       201        0         1   
>      . 
> 5.  2408216        3       901        0         1   
>      . 
>
---------------------------------------------------------
> 6.  2408217        1       101        1         1   
>      1 
> 7.  2408217        2       201        0         1   
>      . 
> 8.  2408217        3       301        0         1   
>      . 
> 9.  2408217        4       301        0         1   
>      . 
> 10.  2408217       5       301        0         1   
>      . 
>
---------------------------------------------------------
> 11.  2408218        1      1301        0         1  
>       . 
> 12.  2408219        1       101        1         1  
>       1 
> 13.  2408220        1       101        1         1  
>       1 
> 14.  2408221        1       101        1         1  
>       1 
> 15.  2408221        2       301        0         1  
>       . 
>
---------------------------------------------------------
> 16.  2408221        3      1114        0         2  
>       . 
> 17.  2408222        1       101        1         1  
>       1 
> 18.  2408222        2       301        0         1  
>       . 
> 19.  2408222        3       301        0         1  
>       . 
> 20.  2408233        1       101        1         1  
>       1 

*
*   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