Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Question with file write


From   Richard Aplenc <raplenc@cceb.med.upenn.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Question with file write
Date   Mon, 01 Mar 2004 12:45:31 -0500

Hi,

I am working with a dataset that has 4 genotypes (gene1, gene2, gene3, gene4) and each genotype may have discordant values for a particular study subject. i.e.

study_id gene1 gene2 gene3 gene4
a-1 ww ww ww vv
a-1 vv ww ww vv
b-1 ww vv ww vv
c-1 ww ww vv vv
c-1 ww ww vv vv


The statalist (ie Nick) had previously helped me identify genotypes that are discordant for one gene for one individual. Now I would like to write only those discordant genotypes out to a .txt file so that I can take it back to the lab. i.e.

study_id gene genotype
a-1 gene1 ww
a-1 gene1 vv

I can do this using a temporary file (see below), but I suspect that using a temporary file is not the most appropriate/elegent way to do this. I'd be most appreciate of anyone's education efforts on my behalf. If you go to AACR or ASH, I'll buy you a beer/coffee there. :)

Thanks in advance.

local genotypes "gene1 gene2 gene3 gene4"
file open discordant using discordant.txt, write replace
file write discordant
foreach gene of local genotypes {
preserve
tempfile data
save "`data'"
keep if disc_`gene' == 1
file write discordant "Study ID" _tab "Gene" _tab "Genotype" _n
local N = _N
sort study_id `gene'
forvalues i = 1/`N' {
file write discordant (study_id[`i']) _tab "`gene'" _tab
(`gene'[`i']) _n
}
restore
}
file close discordant


Richard
--
Richard Aplenc, MD, MSCE
Pediatric Oncology/Stem Cell Transplant
Children's Hospital of Philadelphia
Center for Clinical Epidemiology and Biostatistics
University of Pennsylvania
215-573-0259 (lab)
215-590-4183 (fax)
raplenc@cceb.med.upenn.edu

CONFIDENTIALITY
This email and any attachments may contain confidential information
belonging to the sender that is legally privileged. Any unauthorized
disclosure, copying, distribution, or the unauthorized taking of action
based on the contents of this email is strictly prohibited. If you are
not the named recipient, or have otherwise received this communication
in error, please delete it from you inbox, notify the sender
immediately, and do not disclose its contents to any other person, use
them for any purpose, or store or copy them in any medium.

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index