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

st: Re: statalist-digest V4 #1900


From   evan roberts <eroberts@hist.umn.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: statalist-digest V4 #1900
Date   Wed, 02 Mar 2005 11:53:17 -0600

This is a relatively straightforward way to do it too, and the way the IPUMS suggests
http://www.ipums.umn.edu/usa/chapter5/chapter5.html

cd C:\
use test.dta
sort nh pid
save test.dta, replace

use test.dta
keep nh sid age educ
rename sid pid
rename age spage
rename educ speduc
sort nh pid
save temp.dta

use test.dta
merge nh pid using temp.dta
save newtest.dta

The resulting dataset has everyone in it, including people who don't have a spouse. Use the _merge variable to drop people without spouses.

Evan Roberts

At 01:33 AM 02/03/2005, you wrote:

Date: Mon, 28 Feb 2005 00:59:19 -0500
From: "Kakatua Kutta" <ambush@earthling.net>
Subject: st: data manipulation problem

Dear stata maestros,

I have a following data set

nh pid  sid  age  educ
1    1    2   34    3
1    2    1   29    2
1    3    .   21    2
1    4    .   27    1
2    1    3   44    12
2    2    .   23    9
2    3    1   31    11
2    4    .   19     2
2    5    .   27     3
.
.
.

nh is the household identification no and pid is individual identification
within each household. Sid is the spouse identification no for those
people who are married within a household. So for nh=1, it means pid 1 and
2 are married to each other and for nh=2, pid 1 and 3 are married to each
other.

What I want to do is to make a datasets consisting of household members
married to each other. That is, in the new data set I want to keep , for
nh=1, pid 1 and 2 and for nh=2, pid 1 and 3. So what I am trying to find
that for each nh, take those pid for which sid equals pid from others
observations.

Is there anyway to do it rather than going through each observation
individually?
------------
Evan Roberts
Minnesota Population Center and Department of History
University of Minnesota
<eroberts@pop.umn.edu>
www.pop.umn.edu/~eroberts
*
* 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