What is the purpose of R2 in this discrete voltage regulator circuit?
R2 simply makes sure that there's a certain amount of current flowing through Q1 even if no external load is attached to the circuit. This is called a "minimum load".

It also makes sure that a certain amount of current is flowing through D1, which makes its forward voltage drop have a more stable value, improving the regulation of the circuit overall.

Note that as long as R1 = R2, the current through D1 is independent of the actual value of Vout; it only depends on Vin and the resistor value. The current flowing through R1 is (Vin &#150; Vout &#150; Vbe) / R1. The current flowing through R2 is (Vout &#150; Vf) / R2. If you add these together, the Vout terms cancel, leaving (Vin &#150; Vbe &#150; Vf) / R1.

The only current through these two resistors that doesn't flow through the diode is the base current of Q1, which means that the diode current slightly depends on the amount of current being drawn by the load, depending on the actual gain (current transfer ratio) of Q1. For high loads, this would be a good place for a Darlington.