Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: reshape query


From   "McDermaid, Cameron" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: reshape query
Date   Fri, 3 Jan 2014 18:12:02 +0000

Hi Tim

You mention output rather than further manipulating a reshaped dataset. If you just need output, using your variable names that you provide in your sample source data, would this meet your needs?

tabout age invsurg2 [fweight=age_] using output.txt, replace


-cam  

Cameron McDermaid MHSc
Epidemiologist
Ottawa Public Health
100 Constellation Crescent 26-50
Ottawa ON K2G 6J8
vox 613-580-6744 ext 15321  toll free 1-866-426-8885 ext 15321  
fax 613-580-9601
******************************************
There is no data that can be displayed in a pie chart, that cannot be displayed better in some other type of chart.
                                          - John Tukey 


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Tim Evans
Sent: January 3, 2014 12:02 PM
To: [email protected]
Subject: st: reshape query

Hi all,


I'm using Stata 11.2 and trying to reshape a dataset to an output that I would like.

I am trying to get my data in the format (note that invsurg2 is spurious at the moment and will be dropped when I get to this point)

age	y	n
17	1	0
18	1	0
19	2	0
20	2	0
21	1	0
22	3	0
23	3	1
24	9	0
25	12	5
~~
~~
94	22	108
95	9	87
96	12	65
97	2	44
98	4	16
99	1	11

y and n relate to invsurg2 which is shown below

My initial data look like this:

age	invsurg2	id	age_
17	Y		1		1
18	Y		1		1
19	Y		1		2
20	Y		1		2
21	Y		1		1
22	Y		1		3
23	Y		1		3
24	Y		1		9
25	Y		1		12
26	Y		1		19
27	Y		1		26
28	Y		1		32
29	Y		1		41
30	Y		1		65
31	Y		1		86
32	Y		1		75

Where invsurg2 is a Y/N variable (numeric behind a label), id has been generated using:
bysort age: g id=_n
and age_ currently relates to a count, but for reasons of reshaping, found it helpful to call the variable age_

This run of data runs to age 99, and then is repeated, but for invsurg2==N

I reshape the data using the following:

reshape wide age_, i(id inv) j(age)

Which returns the following:

id	invsurg2	age_17	age_18	age_19	age_20	age_21	age_22	age_23	age_24	age_25	age_94	age_95	age_96	age_97	age_98	age_99
1	Y		1	1	2	2	1	3	3	9	12	22	9	12	2	4	1
2	N		0	0	0	0	0	0	1	0	5	108	87	65	44	16	11

What I have been struggling with is how to complete my final reshape to provide this desired output:

age	y	n
17	1	0
18	1	0
19	2	0
20	2	0

As indicated earlier, invsurg2

I would appreciate any help here.

Best wishes

Tim

**************************************************************************
The information contained in the EMail and any attachments is confidential and intended solely and for the attention and use of the named addressee(s). It may not be disclosed to any other person without the express authority of Public Health England, or the intended recipient, or both. If you are not the intended recipient, you must not disclose, copy, distribute or retain this message or any part of it. This footnote also confirms that this EMail has been swept for computer viruses by Symantec.Cloud, but please re-sweep any attachments before opening or saving. http://www.gov.uk/PHE
**************************************************************************

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


This e-mail originates from the City of Ottawa e-mail system. Any 
distribution, use or copying of this e-mail or the information it 
contains by other than the intended recipient(s) is unauthorized. 
If you are not the intended recipient, please notify me at the 
telephone number shown above or by return e-mail and delete 
this communication and any copy immediately. Thank you.

Le présent courriel a été expédié par le système de courriels de 
la Ville d'Ottawa. Toute distribution, utilisation ou 
reproduction du courriel ou des renseignements qui s'y trouvent 
par une personne autre que son destinataire prévu est interdite. 
Si vous avez reçu le message par erreur, veuillez m'en aviser par 
téléphone (au numéro précité) ou par courriel, puis supprimer 
sans délai la version originale de la communication ainsi que 
toutes ses copies. Je vous remercie de votre collaboration.



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index