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?
Year Fixed effect xtlogitDear All Please, I have seen some posts related to many fixed effect, but I don’t find my case solut…
Variable SEXHello!!!! I would like you to help me: I want to generate the sex through the names, I know that it…
Mixed-Effects Linear Model Set-upHi, I would like to run a mixed-effects linear regression model with cesd as my outcome variable an…
Count Number of Each Age Observation Across Years and Not Include Certain Data ObservationsDear all, I am using Stata 16, on mac. I have taken a snapshot of dataset I am working with. Array …
Count Number of Each Age Observation Across Years and Not Include Certain Data ObservationsDear all, I am using Stata 16, on mac. I have taken a snapshot of dataset I am working with. Array …
Subscribe to:
Post Comments (Atom)
0 Response to How to write a text.file using loops?
Post a Comment