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
Defining duplicates through extracting day from date-time variableHi all, I have scoured statalist for some time but have not found the answer to this question. Fir…
Intended Nickell bias to test the usefullness of different fixed effectsHi all, I am working on panel data and I assume that at least one of my explanatory variables is en…
Find the the variable with highest value and mark this as 1, while the other variables are marked 0Hello all, I have a data set that looks like this: Code: input int year float(A B C D E) 1950 .3…
How to mix the obs of two variables?Hello everyone, This is my database. Each org_uuid is matched with a specific investor_uuid. This a…
Generate new variable(s) conditional on different variables taking a specific valueDears, I would generate new variables every time that corr_tof* takes the same value as tof. Here b…
Subscribe to:
Post Comments (Atom)
0 Response to Creating tempfiles in a forvalue loop
Post a Comment