Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Antwort: st: LA-AIDS model: saving parts of a dataset using forvalue
From
Christian OTCHIA <[email protected]>
To
[email protected]
Subject
Re: Antwort: st: LA-AIDS model: saving parts of a dataset using forvalue
Date
Mon, 15 Nov 2010 06:00:04 -0800 (PST)
Rich,
I am sorry for not being so clear in my post. Actually, I got my mistake
corrected already.
However, I think that nested loop might help me to use the loop efficiently.
The following code expresses what I wanted to do.
I want to aggregate the "academic hours" by year and number of students.
Variable "students" has value from 2 to 5. Therefore, I want to create 4
other variables which contains "aggregated academic hours" of each number of
students (hour_2, hour_3. hour_4, hour_5).
I did it by creating many files but I think that my code can be improved
substantially.
Any improvement or comments will be appreciated.
Regards,
Christian
****My code********
cd "c:\data\stata"
use http://www.stata-press.com/data/r11/college.dta
*aggregate "academic hours" by year and number of students
collapse (sum) hour, by(year number)
save file1, replace
*4 other variables which contains "aggregated academic hours" of each number
of students
forvalues i=2/5{
preserve
keep if numb==`i'
rename hour hour`i'
drop number
save numb_`i'
restore
}
* Merging files
use numb_2, clear
forvalues i=3/5{
merge 1:1 year using numb_`i'
drop _merge
save file02, replace
}
preserve
*****End****
--
View this message in context: http://statalist.1588530.n2.nabble.com/LA-AIDS-model-saving-parts-of-a-dataset-using-forvalue-tp5735067p5739918.html
Sent from the Statalist mailing list archive at Nabble.com.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/