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

st: AW: simple sum() question

From   "Martin Weiss" <>
To   <>
Subject   st: AW: simple sum() question
Date   Wed, 15 Apr 2009 17:15:00 +0200


I am betting that you want a count of visits, not a running sum, but correct
me if I am wrong...

set obs 400
egen float patient = seq(), from(1) to(400) block(4)
egen float visit = seq(), from(1) to(4) block(1)

//not strictly necessary
xtset patient visit

//less than 4 visits for some
replace visit =. if runiform()<0.05

bys patient: egen overallvisits=count(visit)

l in 1/20, sepby(patient) noo


-----Ursprüngliche Nachricht-----
[] Im Auftrag von Shehzad Ali
Gesendet: Mittwoch, 15. April 2009 16:48
Betreff: st: simple sum() question


I have a simple question about summing across observations. I have 100 
patients (variable: patient_id) in the dataset, each had clinic visits 
(variable: clinic) and hospital visits (variable: hospital) recorded at 
weeks 4, 8, 12 and 16. The dataset is long and hence I have 400 
observations (one observation per patient per time point).

I want to sum the clinic visits for each patient (across all 4 visits) 
bearing in mind that some patients had less than 4 visits. So effectively I 
want to generate a new variable that will produce the sum of clinic visits 
for each patient.

Any help would be appreciated.

Thank you,
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index