I have a dataset where I want to get the sample size for each race category by year and sector (occupation). My race variable name is wbho and the values are White (1), Black(2), Hispanic(3), Others(3). I wrote a forval loop to do this, but I can't save them as different tempfiles inside the loop (since the race variable name is the same for each collapse result). In the end, I want to append the 4 tempfiles. How can I do that? Here is my loop:
```
forval i=1/4 {
use ${data}wbho.dta, clear
gcollapse (count) wbho if wbho==`i', by (year docc03)
}
```
After each tempfile is saved, I was going to append like this:
```
use `part1', clear
append using `part2'
append using `part3'
append using `part4'
tempfile overall
save `overall'
```
Related Posts with Creating tempfiles in a forvalue loop
Using foreach for two set of groupsDear All, I have two groups of countries and pairwise data- importers and exporters. Eg. Importers=…
Using Weights for countries in Survey DatasetHello everyone, I am working with 2 waves (5 and 6) of World Value Survey in Stata 15 and I am anal…
Foreach and gen ? Help please(Don't speak english, Hope you can understand) Hi, I was wondering if is possible making a loop to f…
Combine two strings with entry that has more informationDear statalists, I have two variables that capture the same thing but with differing precision. One…
estimate of theta = . in Cox shared frailty model using MIDear Statalist Members, I am not able to see the estimate of theta or the se of theta using e-return…
Subscribe to:
Post Comments (Atom)
0 Response to Creating tempfiles in a forvalue loop
Post a Comment