For Values (Loops)
In this exercise you will use forvalues to loop over survey waves and compute
summary statistics.
-
Use
tabto determine how many survey waves (wave) are in the data set. How many waves are in the data set? - Use a
forvaluesloop to summarizeyield_kgseparately for each wave. Your code should:- Loop over all integer values of
waveobserved in the data (for example,1/3if there are 3 waves). - For each wave:
- Display a header line like
"Wave 1". - Run
summarize yield_kg if wave == ....
- Display a header line like
Example structure (modify the range to match your data):
forvalues w = 1/3 { display "------------------------" display "Summary for wave `w'" summarize yield_kg if wave == `w' }What is mean yield in each wave?
- Loop over all integer values of
- Extend your loop so that for each wave it also summarizes
nitrogen_kg. What is mean nitrogren use in each wave?