Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: -hhset- hrespnr?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: -hhset- hrespnr?
Date   Fri, 14 Mar 2008 17:03:46 -0000

As hinted in my last post in this thread, 

<http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist
.0803/date/article-322.html>

which you did not respond to, you need to reshape. That may or may not
mean using
-reshape-. Check out the help, manual entry and FAQs for -reshape- in
any case. You will need it sooner or later. 

You want to ignore everyone not a wife or a husband 

. drop if missing(agewife) & missing(agehusband) 

Then you could just exploit the fact that wife and husband are paired: 

. bysort hhid: replace agewife = agewife[3 - _n] if missing(agewife)
. bysort hhid: replace agehusband = agehusband[3 - _n] if
missing(agehusband)

That may look a little tricky. Under -by:- the observation number _n is
calculated
within groups defined by the -by:- and takes on values 1 or 2 for the
two observations of spouses. If _n is 1 then 3 - _n is 2 and if _n is 2
then 3 - _n is 1. Thus we always look in the other observation for the
non-missing value when any value is missing. 

Alternatively, we could use a standard technique, sorting the
non-missings into the 
first observation for each household: 

. bysort hhid (agehusband) : replace agehusband = agehusband[1] 
. bysort hhid (agewife) : replace agewife = agewife[1]

Now the two observations for each -hhid- are identical and you can
-keep- one, or
-drop- one (same result). 

. by hhid : keep if _n == 1 

Nick
[email protected] 

Nirina F

Yes, I agree because I only have one household data.
And that is why I tried to use -hhset- but it did not work but I will
try again and let you know.
This is what I get which gives me zero observation when I run reg.
list   hhid linenum  ageofwife  ageofhusband
               +----------------------------------+
               hhid   linenum   ageofwife   ageofhusband
               ----------------------------------
       1.      f2                 1       .                52
       2.      f2                 2      38                .
       3.      f2                 3       .                  .
       4.      f2                 4       .                   .
       5.      f2                 5       .                   .
               ----------------------------------
       7.      f41               1       .                33
       8.      f41               2      22                 .
       9.      f41               3       .                   .
       10.    f41               4       .                   .

What I would like to get something like:

       +----------------------------------+
               hhid   linenum   ageofwife   ageofhusband
               ----------------------------------
       1.      f2                 1       38              52
       2.      f41               1       22                33

but I don't know how to do it.

On 3/7/08, Richard J Stoll <[email protected]> wrote:

> Everyone is a husband or a wife right?  So ageofwife is missing for
all
> husbands,  therefore all those cases are dropped.  Ageofhusband is
> missing for all wives, so you lose the rest of the cases.....
>
> On Fri, 7 Mar 2008, Nirina F wrote:
>
> > Dear Nick,
> >
> > Thank you for taking the time to respond.  I understand what you
mean but
> >
> > actually, what I meant was that  if I run
> >
> > "reg income ageofwife ageofhusband schoolingofwife
schoolingofhusband "
> >
> > it gives me 0 observation because of how the explanatory variables
> > were generated:
> >
> >  ageofwife=age if wife==1
> > ageofhusband=age if husband==1
> >
> > then used together ends up in intersection and here comes my
problem.

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