Translations of this page?:
 

FAQ list and illustrative examples

Here we will build a collection of “how to” or answers to common problems. For smaller issues a short description is shown, and for larger problems separate pages will be used.

How to: generate complete dataset

Author: JLauritsen 2009/03/04

With the command *generate* you can develop complete datasets from scratch.

Example: We need a file for 50 patients with one record for each day from 1 to 30 for all of them. Later on we will merge this file with patient medication data to see the pattern of pain medication over the course of time from surgery to exit from hospital.

* how to generate a dataset with many observations
close
* generate 30*50 observations:
generate 2500
* generate a variable containing day values from 1 to 30. 
* _n is the record or observation number
gen i thisday = ((_n-1) mod 30) + 1
* now we need the id number for each patient to be repeated 30 times:
gen i id = 1
id = iif(id = 1,iif(_n=1,1, id[_n-1]+1), id[_n-1])
* the trick was to take the value depending on which day of the sequence
labeldata "Keyfile for one observation on each day for all patients"
* verify that we have the data:  (look at min and max)
describe id 
Select if id < 50    // an alternative to generating correct numbers above is to select here 
savedata day2day /replace

Notice you can add formula's: $$sum_i i$$ $$sqrtx$$

Next FAQ

 
epidata/example.txt · Last modified: 2011/01/07 11:33 (external edit)
 
Except where otherwise noted, content all EpiData wiki Content is licensed as Creative Commons License Recent changes RSS feed Driven by DokuWiki