We present three examples for three different types of data structures. Let’s first create a sample data set. Each of the examples below will be based on some version of the same data set. It can be grouped or reshaped.

clear set seed 12357 set obs 100 gen id = _n gen year = mod(_n, 10) + 1 tab year gen x = uniform()>.6

**Example 1**: Testing on linear trend of proportions using the
individual data set

**Example 2**: Testing on linear trend of proportions using the
grouped data

**Example 3**: Testing on linear trend of proportions using the
grouped data set in wide format

You data might be in grouped data format, but it is also wide, similar to
the data listed below. You can use a Stata user-written program called **ptrend** to perform the test. You may have to download it from the
internet and can do so by using "**search ptrend**" command.

preserve contract year x, freq(freq) reshape wide freq, i(year) j(x) list+----------------------+ | year freq0 freq1 | |----------------------| 1. | 1 6 4 | 2. | 2 7 3 | 3. | 3 4 6 | 4. | 4 6 4 | 5. | 5 4 6 | |----------------------| 6. | 6 5 5 | 7. | 7 6 4 | 8. | 8 7 3 | 9. | 9 4 6 | 10. | 10 6 4 | +----------------------+ptrend freq1 freq0 year+------------------------------+ | freq1 freq0 _prop year | |------------------------------| 1. | 4 6 0.400 1 | 2. | 3 7 0.300 2 | 3. | 6 4 0.600 3 | 4. | 4 6 0.400 4 | 5. | 6 4 0.600 5 | |------------------------------| 6. | 5 5 0.500 6 | 7. | 4 6 0.400 7 | 8. | 3 7 0.300 8 | 9. | 6 4 0.600 9 | 10. | 4 6 0.400 10 | +------------------------------+ Trend analysis for proportions ------------------------------ Regression of p = freq1/(freq1+freq0) on year: Slope = .00303, std. error = .01732, Z = 0.175 Overall chi2(9) = 5.051, pr>chi2 = 0.8299 Chi2(1) for trend = 0.031, pr>chi2 = 0.8611 Chi2(8) for departure = 5.020, pr>chi2 = 0.7554restore