Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Writing output from byvar and tab to dataset


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Writing output from byvar and tab to dataset
Date   Sat, 10 Nov 2007 12:04:37 +0000 (GMT)

--- Olalekan Uthman <[email protected]> wrote:
> I am trying to write results fom byvar and tab result
> to a dataset (e.g):
> 
> . webuse hiv
> 
> . byvar  cd4: tab  hiv
<snip>
> cd4	hiv0	hiv1	total	
> 0	1	2	3		
> 1	2	3	5
> 2	3	1	4	

First of all note that -byvar- is a user written command (and pretty
old). The way you use it can also be done with official Stata's -by- or
-bysort- commands. You can get the dataset you want by using a
combination of -contract-, -reshape-, and -egen-, as is shown in the
example below. Also see the helpfiles of those commands for the
details.

*------------- begin example -------------
webuse hiv, clear
bys cd4: tab  hiv [fw=f]
contract hiv cd4 [fw=f]
reshape wide _freq, i(cd4) j(hiv)
egen tot = rowtotal(_freq0 _freq1)
list
*------------ end example ---------------- 
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      ___________________________________________________________ 
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  http://uk.promotions.yahoo.com/forgood/environment.html
*
*   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