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

RE: st: RE: Bysort on non-selection variables


From   "Deborah Garvey" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Bysort on non-selection variables
Date   Tue, 19 Jul 2005 15:46:01 -0700

Dear Nick,

Thanks for suggesting the -stable- option.  It crossed my mind after reading the -sort- thread from last month.  However, the -stable- option with -sort- doesn't keep the data in serial/pernum order at the -bysort- command.  Did I mess  something up?  Test commands and sample output below.

Thanks,

Deb

. use "C:\dlgarvey\Census data\IPUMS data\temp.dta", clear
. sort serial pernum, stable
. gen test=momloc
. bysort serial (test): replace test=8 if momloc==1
(30 real changes made)
. l serial pernum momloc test

	serial   pernum   momloc   test 
	----------------------------------
1.	2408215        1        0      0 
2.	2408215        2        0      0 
3.	2408216        2        0      0 
4.	2408216        3        0      0 
5.	2408216        1        0      0 
	----------------------------------
6.	2408217        2        0      0 
7.	2408217        1        0      0 
8.	2408217        5        2      2 
9.	2408217        4        2      2 
10.	2408217        3        2      2 
	----------------------------------
11.	2408218        1        0      0 
12.	2408219        1        0      0 
13.	2408220        1        0      0 
14.	2408221        3        0      0 
15.	2408221        2        0      0 
	----------------------------------
16.	2408221        1        0      0 
17.	2408222        1        0      0 
18.	2408222        2        1      8 
19.	2408222        3        1      8 
20.	2408233        2        0      0 
	----------------------------------
21.	2408233        1        0      0 
22.	2408233        4        2      2 
23.	2408233        3        2      2 
24.	2408323        2        0      0 
25.	2408323        5        0      0 
	----------------------------------
26.	2408323        1        0      0 
27.	2408323        3        2      2 
28.	2408323        4        2      2 
29.	2408423        1        0      0 
30.	2408423        3        0      0 
	----------------------------------
31.	2408423        2        1      8 
32.	2408423        5        3      3 
33.	2408423        4        3      3 
34.	2408434        1        0      0 
35.	2408434        2        0      0 
--Break--

----
Date: Tue, 19 Jul 2005 00:13:34 +0100
From: "Nick Cox" <[email protected]>
Subject: st: RE: Bysort on non-selection variables

Two suggestions: 

1. Do you also need a unique id? 

gen uniqueid = _n 

2. Check out the -stable- option. 

Nick 
[email protected] 

Deborah Garvey, Ph.D.

> I have data with a household identifier (serial) and a person 
> locator within each household (pernum).
> 
> Is there any way to maintain a sort order of PERNUM within 
> SERIAL, i.e., the results of a command like -sort serial 
> pernum-  for a -bysort- that is sorted on a within-household 
> indicator variable, i.e. -bysort serial (indicatorvar): 
> several expressions to condition the value of a PERNUM-level variable-
> 
> My question may seem odd, but the person's location in the 
> household is an important criterion for determining the 
> indicator variable's value. Unfortunately, the value of the 
> indicator variable may be the same for more than one person 
> in the household, so I can't use -bysort serial pernum 
> (indicatorvar):  stuff-


******************************
Deborah Garvey, Ph.D.
Department of Economics
Kenna Hall
Santa Clara University
Santa Clara, CA  95053
408/554-5580
408/554-2331 (FAX)
[email protected]    
http://lsb.scu.edu/~dgarvey
**********************************


This message scanned for viruses and SPAM at SCU (MGW2)

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