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

st: Collapse


From   "Jason Payne" <[email protected]>
To   <[email protected]>
Subject   st: Collapse
Date   Thu, 12 Feb 2004 11:18:48 +1100

Dear all,

I need help regading the collapse command.

I want to collapse by personid, and keep the values for all variables corresponding with the earliest(minimum) referralid. I want a final file that has the first referral for each person including the date and agency of that referral. The problem I am having is that the collapse is defaulting to give the mean of the date and agency (or the minimum).

For instanace

Personid	Referralid	Referraldate(d.m.y) Referringagency
25		1		21.12.03			291			
25		24		31.01.04			290
25		75		25.02.04			292
78		4		10.11.03			290
78		22		12.12.03			275

I want to collapse by the minimum value of referralid but I dont want the minimum or mean value for referraldate or referringagency. I want the values that correspond to the minimum referralid.

The result I want is:
Personid	Referralid	Referraldate(d.m.y) Referringagency
25		1		21.12.03			291			
78		4		10.11.03			290


This is probably very easy, and i apologise for the trouble, but having worked with SPSS for many years now, I am trying to find my way through STATA logic as best as possible. 

Regards

Jason Payne

____________________________________
Jason Payne
Violence, Property Crime and Drugs
Australian Institute of Criminology
GPO Box 2944 Canberra ACT 2601

E-mail: [email protected]
Tel +61 2 6260 9283 Fax +61 2 6260 9201

Visit the AIC homepage www.aic.gov.au


-----Original Message-----
From: Jason Payne 
Sent: Thursday, 12 February 2004 9:56 AM
To: [email protected]
Subject: RE: st: Transformations


Thank you for your help,

Is there a way to list multiple cases that dont fit a standard expression in the replace command. for example:

replace var1=1 if var2==1 or 3

I want cases 1 and 3 to have value 1 for var1, but not case 2 and rather than writing the whole syntax twice, i would like to shorten it: 

replace var1=1 if caseid==1
replace var1=1 if caseid==3

Any clues?

Regards

Jason Payne
____________________________________
Jason Payne
Violence, Property Crime and Drugs
Australian Institute of Criminology
GPO Box 2944 Canberra ACT 2601

E-mail: [email protected]
Tel +61 2 6260 9283 Fax +61 2 6260 9201

Visit the AIC homepage www.aic.gov.au


-----Original Message-----
From: Richard Williams [mailto:[email protected]]
Sent: Wednesday, 11 February 2004 12:53 PM
To: [email protected]; [email protected]
Subject: Re: st: Transformations


At 11:43 AM 2/11/2004 +1100, Jason Payne wrote:
>Dear STATAlistservers
>
>I am trying to transform data in variables.  What is the equivalent STATA>
 syntax for this SPSS command
>
>if (var1=2) var2=1.

Stata does things kind of backwards from SPSS:

gen var2 = 1 if var1==2

Note the ==

If var2 already exists, instead say

replace var2 = 1 if var1==2

But, what do you want when var1 does not equal 2?  Missing?  A 0-1 
dichotomy? There may be some other ways to approach this, depending on whaty
 our ultimate goal is.

>This syntax only works if you want to create a new variable, however in 
>some cases I might with to modify an existing variable for one case 
>only.  This is particularly useful in cleaning string variables where 
>there are spelling mistakes.  In SPSS I would just type:
>
>if (caseid=1) stringvar='SPSS'.
>if (caseid=2) stringvar='STATA'.

replace stringvar="SPSS" in 1
replace stringvar="STATA" in 2

I'm assuming these are the first and second cases in your data.  If not 
necessarily so, and caseid is a variable in your data set, then try

replace stringvar="SPSS" if caseid==1
replace stringvar="STATA" if caseid==2

Or, just go in to the data editor and do it!  Lot easier sometimes really.

-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX:    (574)288-4373
HOME:   (574)289-5227
EMAIL:  [email protected]
WWW (personal):    http://www.nd.edu/~rwilliam
WWW (department):    http://www.nd.edu/~soc

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


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

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


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

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