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

st: Re: help on data manipulation


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: help on data manipulation
Date   Fri, 29 Jul 2005 14:40:14 -0400

How about:

gen masterstate=state if custnum==master
bysort master (masterstate): replace masterstate=masterstate[_N]

The first command defines the masterstate for master customers. The second command copies the masterstate to the other customers with the same master (since blanks come before filled in values when sorting strings). If state is a labeled numeric variable, then sorting does the reverse and you would need to change the second command to end with masterstate[1].

Michael Blasnik
[email protected]

----- Original Message ----- From: <[email protected]>
To: <[email protected]>
Sent: Friday, July 29, 2005 2:21 PM
Subject: st: help on data manipulation



Hello List,

    I have a data set like the following:

custnum    master      state
-----------------------------
712875     712875       TX
182579     712875       CA
376083     712875       FL
716228                  TN
604906     312456       IL
177414                  PA

I need to redefine "state" variable for customers "custnum" such that
when there is a master customer # "master", all customers under that
master will have the same state. For example, custnum 712875, 182579, &
376083 have master 712875 and when custnum="712875" & master="712875",
the state is "TX". So, the data needs to look like:

custnum    master      state
-----------------------------
712875     712875       TX
182579     712875       TX
376083     712875       TX
716228                  TN
604906     312456       IL
177414                  PA

Can anyone please help me with this?

Thank you.

Sincerely,
Pinaki Mitra
*
*   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