datacarpentry / stata-economics

Economics Lesson with Stata
https://datacarpentry.org/stata-economics/
Other
27 stars 20 forks source link

Episode 3: missing `collapse` exercise #104

Open csokaimola opened 2 months ago

csokaimola commented 2 months ago

What is the problem?

There is no exercise with collapse, even though it is mentioned in the "Overview" and "Key points" sections as well. It could be included in the "Aggregate" section, after egen average_census_year = mean(censusyear), by(incomegroup) in the following way: preserve collapse (mean) average_census_year=censusyear, by(incomegroup) save "data/derived/censusyear.dta", replace restore

This gives the same result as the egen command before, with the difference that it saves the aggregate statistics to a separate dta file. Students can load the generated datafile and check to see. This is a typical example of the collapse as it is often used together with preserve and restore. With this exercise, we can also show the importance of preserve and restore, and highlight that save should be used together with the option replace.

Location of problem (optional)

Episode 3

csokaimola commented 2 months ago

relates to #82