The easiest way is to first subset your data:
sysuse uslifeexp, clear
set seed 12345
// preserve
keep if year >= 1946 & year <=1957
drop if inlist(year, 1948, 1952, 1954)
tempname sim
postfile `sim' id year1 year2 year3 using results, replace
forvalues i = 1 / 500 {
generate random = runiform()
sort random
post `sim' (`i') (year[1]) (year[2]) (year[3])
drop random
}
postclose `sim'
// restore
Note the commented out preserve
/ restore
commands, which can keep your data intact in case you do not want to only have the reduced dataset after the simulation.
As before the results are stored in a new dataset result
:
use results, clear
list in 1/10
+----------------------------+
| id year1 year2 year3 |
|----------------------------|
1. | 1 1955 1953 1946 |
2. | 2 1953 1946 1949 |
3. | 3 1949 1953 1946 |
4. | 4 1949 1957 1956 |
5. | 5 1946 1951 1950 |
|----------------------------|
6. | 6 1953 1946 1951 |
7. | 7 1957 1947 1946 |
8. | 8 1949 1957 1947 |
9. | 9 1947 1956 1949 |
10. | 10 1953 1949 1957 |
+----------------------------+