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
Problems combining multiple responses according to age ranges Hi everyone , I have difficulties to find the right command with conditions that make it possible t…
GLM- convergence not achievedhello everyone, I am new to statalist. Please pardon if the language is unclear. I am writing me the…
Creating new var w/ multiple values of another varHello, I have two variables, IS and Code. I would like IS to take on different values depending on w…
Creating fiscal month given fiscal year end monthDear Stata Users, Please, help me with the following issue. I have a data uploaded below. What I ne…
multivariate analysis from a scoreDear friends, I am trying to analyze the effect of this three variables (ml, mms, mic) in the outco…
Subscribe to:
Post Comments (Atom)
0 Response to Forvalues loop using if and preserve / restore, but cannot save files
Post a Comment