Hello everyone! I am trying to solve how to write a text.file using loops. I have hit an obstacle and I was hoping that you all could give me direction.
Here is the scenario. I have a dataset with 20 observations. There is one variable in this dataset and it is a string variable (str35) that stores the name of the observation. I want to generate a text file that will create a list of the 20 observation names which are stored as a string variable in the dataset.
The Stata Code below runs a loop across all 20 observations in the dataset and for each one it types "Observation Name." Which results in the a text file with Observation Name written out 20 times. For each observation (i), I want to write out the observation name that is stored in the string variable for that observation in the dataset. How can I do this?
So the final result would be a list of 20 different names for each one of the 20 observations.
Stata Code:
file open textfile using textfile.txt, text write replace
describe
local N = _N
forvalues i = 1 / `N' {
file write textfile "Observation Name" _n
}
file close textfile
Related Posts with How to write a text.file using loops?
STATA or other chat / IRC / live realtime help resource? Codementor?Hi all, I am a newcomer to STATA and diving in to the manuals tutorials helpfiles. and now recently …
forvalue index included in csv file nameHey everyone, I'm attempting to assemble a panel dataset using a handful of CSV files each of which…
How to execute some commands in .do according to conditions?I want to rename the varlists in different files having different the numbers of varlists. e.g…
dataset description that appears with 'describe' commandHi again folks, the describe command generates an overview of the dataset as well as "a brief descri…
External partial validation of a Cox prognostic model in Stata: Without access to individual development dataHi, I aim to perform an independent external validation of a published cox prediction model. From t…
Subscribe to:
Post Comments (Atom)
0 Response to How to write a text.file using loops?
Post a Comment