Dear all!
I am using the - file write - command to write a series of lines to a text file. The text file is used as a parameter file for an external program.
The text file should contain information on several variables for several different observations and I thus like to loop over observations and use an - if - condition to write information from the correct observation in each line. Hovwever, the - file write - command does not seem to allow - if - conditions. I have tried using the - if - command with code along these lines:
tempname FILE
file open `FILE' using test.ajo, write replace
sum id
local minid = r(min)
local maxid = r(max)
forvalues i = `minid'(1)`maxid' {
if id=`id' {
file write `FILE' %7.1f (species) _n
}
}
but this only checks the first observation and stops. I can make it work using - macro - which can take - if -conditions
forvalues i = `minid'(1)`maxid' {
sum species if treid==`l'
local species = r(min)
file write `FILE' %7.1f (`species') _n
}
}
but for several variables for several observations, this seems to be a bad solution.
Any hints to how I can use - file write - and loop over observations or use the - if- condition?
best regards,
Even
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/