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: Increase observations by group and then calculate percentages


From   Catherine Tisch <[email protected]>
To   [email protected]
Subject   st: Increase observations by group and then calculate percentages
Date   Thu, 03 Nov 2011 15:14:21 +1300

Hi all

I'm hoping someone can help me with my problem - I'd like to insert an
observation after every group and then create percentages by group in my
panel dataset.

My dataset looks something like this:

AreaID	Ethnicity	Sex1Age1	Sex2Age1	Sex1Age2
Sex2Age2	and so on....	 
1	GroupX	18		16
1	Total		57		21
2	GroupX	33		81
2	Total		528		147
and so on....

Ethnicity is stored as a string, all other variables are stored as
float.  I have approximately 2000 AreaIDs and 16 Sex/Age groups.  I am
using Stata 11.1.

I'm hoping my final dataset might look something like this:

AreaID	Ethnicity	Sex1Age1	Sex2Age1	Sex1Age2
Sex2Age2	and so on....	 
1	GroupX	18		16
1	Total		57		21
1	PercentX	31.6		76.2
2	GroupX	33		81
2	Total		528		147
2	PercentX	6.3		55.1
and so on.....

Where PercentX is GroupX/Total for each AreaID by the Sex/Age variables.

I think the first stage I need to do is increase the number of
observations in my dataset by using -set obs-.  I tried

set obs `=_N+1', by AreaID

but got the error message 'options not allowed'.  How can I get around
this?  

Once I get that sorted, the second stage is calculating percentages and
I think I need to use -by- function and any suggestions would be most
welcome.  


Cheers
Catherine
  



This email may be confidential and subject to legal privilege, it may
not reflect the views of the University of Canterbury, and it is not
guaranteed to be virus free. If you are not an intended recipient,
please notify the sender immediately and erase all copies of the message
and any attachments.

Please refer to http://www.canterbury.ac.nz/emaildisclaimer for more
information.

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


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