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
error with mi estimate: factor-variable operators not allowedHi everyone, In the code below, I am trying to compare the coefficients across two regressions. Howe…
how to fix heteroskedasticity, autocorrelation in stata 14.2I am working for my thesis with panel data where N> T (N~700, T=4 as the attached file ). I carri…
-logit- model excluding observations**Hi, I'm running a -logit- model on a dataset of >4000 observations, but when I get the output us…
How to create a graph from mixed effect linear coefficientDear Statalisters, I am using a mixed-effect linear model and I want to plot the coefficient of the…
Using 'forvalues' when some data files are missing in betweenI'm trying to run a loop in which I append some .dta files in multiple folders. The path looks like …
Subscribe to:
Post Comments (Atom)
0 Response to Forvalues loop using if and preserve / restore, but cannot save files
Post a Comment