Dear all,
First of all, happy new year!
I am writing to ask a question about using a loop with `if', combined with preserve/restore.
The following posts are what I have read so far:
https://www.stata.com/statalist/arch.../msg01117.html
https://www.stata.com/statalist/arch.../msg00105.html
https://www.stata.com/statalist/arch.../msg00484.html
https://www.statalist.org/forums/for...d-saving-files
https://www.stata.com/support/faqs/p...-if-qualifier/
I have a program defined as `match', which requires one argument:
capture program drop match
program define match
keep if ~~~
by var1 : ~~~
end
Using the program above, I want to do a loop using forvalues:
forvalues t=100(1)200{
if t==100 {
preserve
match `t'
save data.dta, replace
restore
}
else {
preserve
match `t'
append using data.dta
save data.dta, replace
restore
}
}
If I run this code, however, I get `data.dta not found' and the loop stops right away.
This loop works only if data.dta is already saved: Thus, I am running the loop after I saved an empty dta file using a command below:
save data.dta, replace emptyok
Although I got it solved, but I want to know why it needs an empty dta file first; should not `replace' option enough to ensure save command to run, if there is no data.dta file?
Related Posts with Forvalues loop using if and preserve / restore, but cannot save files
Publishing Regression Coefficients and Elasticity in the same reportHi Statalisters! Beginner here. I ran several regular (OLS) regressions and calculated the elastici…
How to create a new variable that identifies all possible combination of valid choicesI have a dataset with data on exam results for students. There are 20+ subjects, of which a student …
reghdfe - difference between robust and cluster errorI ran a regression with reghdfe on multiple imputation datasets, The data includes 500 organizations…
How can I access, and refer to the panel and time variable in a dataset that has been -xtset- ?Good morning, I am writing some program that is working on data that is -xtset-. In the program I n…
twoway by group titlesHi there Does anyone know how to rename the titles of each graph when using the by() option? For e…
Subscribe to:
Post Comments (Atom)
0 Response to Forvalues loop using if and preserve / restore, but cannot save files
Post a Comment