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

Re: st: Question with file write


From   Dan Blanchette <[email protected]>
To   [email protected]
Subject   Re: st: Question with file write
Date   Mon, 1 Mar 2004 13:54:36 -0500 (EST)

I don't see why you are even using a temporary data file.  The -preserve- and
-restore- are taking care of your data and your -file- command is writing
out to a text file.  It's not clear to me what the purpose is of saving the
data to a temporary file.

This is my version of your program:

 local genotypes "gene1 gene2 gene3 gene4"
 file open discordant using discordant.txt, write replace
 file write discordant  /* not sure if this line is doing anything */
 foreach gene of local genotypes {
  preserve  /* makes a copy of your data in it's current state as a temporary file on your hard drive */
  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 /* replaces data in memory with last preserved copy of data */
 }
 file close discordant


Dan Blanchette
Carolina Population Center - UNC-CH
[email protected]


> From 	  Richard Aplenc <[email protected]>
> To 	  [email protected]
> 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)
> [email protected]
>
> 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index