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]

Re: st: reshape command without a j( ) variable using Stata 8


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: reshape command without a j( ) variable using Stata 8
Date   Tue, 15 Feb 2011 16:58:08 +0000 (GMT)

--- On Tue, 15/2/11, Karen Rappaport wrote:
> My data is a long data set that contains information about
> a substance (X) in supplements, <snip> some patients take.
> Each supplement a patient takes that contains X is a separate 
> observation. <snip> I want to calculate the amount of X 
> patients are getting through supplements. 

Sounds more like a -bysort- problem than a -reshape- problem
to me:

*--------------- begin example --------------
clear
input pat_id drug_id x
      1      1       5
      1      2       4
      2      3       3
      3      1       3
      3      3       6
      3      4       2
end

bys pat_id: egen totx = sum(x) 
list, sepby(pat_id)
*-------------- end example -------------------
(For more on examples I sent to the Statalist see: 
http://www.maartenbuis.nl/example_faq )

Note for users of more recent versions of Stata: the 
-egen- function -sum()- has been renamed to -total()-.

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

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