For Each (Loops)
This exercise uses foreach to loop over lists of variables.
- Use
foreachto run a one-way tabulation (tab) for the following shock indicator variables:crop_shockpests_shockrain_shockdrought_shockflood_shock
How many plots experienced each type of shock?
- Modify the loop so that it also calculates the share of plots that experienced the shock (i.e., where the shock variable == 1). For each shock, use
sum,if, andr(mean)to store that share in a local macro named`share_`shock'`and display the result as:
* Print as percent with one decimal place
display "About " %4.1f (100*`share_`shock'') "% of plots experienced a `shock'."
What share of plots experienced each type of shock?