Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: RE: Re: Writing values to a file

From   Nick Cox <>
To   "''" <>
Subject   st: RE: Re: Writing values to a file
Date   Wed, 8 Dec 2010 15:35:40 +0000

I just wouldn't use -file write- for this purpose. Consider some variant on 

keep if ld <= 0.001 
gen long order = _n
bysort repeat (order) : keep if _n == 1 
outsheet group repeat l ls e using whatiwant.txt 

The first line might be ... ld > 0.001: I can't work out which way round you are selecting. 


Janet Hill

I would be grateful for some advice on writing a value to a file. I have a dataset where I need select a particular value, the first value exceeding a threshold value,and the process is repeated over 240 groups. I can list the values but I am unable to write the values to a file for subsequent use. My code - and I know it is awful programming - is:

capture : file close myfile
file open myfile using "elong.txt", write replace
	file write myfile ("repeat,e") _n
capture : drop marker
gen marker=0
forvalues i=1/24{
replace marker=1 if repeat==`i' & ld > 0.001
su id1 if marker==0 & repeat==`i'
list group repeat l ls e if repeat==`i' & id1==r(min)
	file write myfile (e) if repeat==`i' & id1==r(min)
	file write myfile ","
	file write myfile (`i') _n
file close myfile

*   For searches and help try:

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