I built two new curvature based elbow methods and so variables: curvaturelayer and curvaturelayerrestricted. They use the method described below and are identical except that curvaturelayerrestricted can't select layer 2 (both can't select the first and last layers as they use central second differences).
For the example cities we have:
{| class="wikitable" style="vertical-align:bottom;"
|-
! place
! statecode
! year
! numstartups
! elbowlayer
! finallayer
! curvaturelayer
|-
| Menlo Park
| CA
| 2,006
| 68
| 4
| 51
| 4
|-
| San Diego
| CA
| 2,006
| 220
| 3
| 184
| 181
|-
| Campbell
| CA
| 2,006
| 38
| 3
| 26
| 8
|-
| Charlotte
| NC
| 2,006
| 30
| 3
| 30
| 28
|-
| Waltham
| MA
| 2,006
| 106
| 3
| 58
| 55
|}
For these city-years, the curvaturelayer is the same as the curvaturelayerrestricted. As you can see, it is all over the place!
====New MaxR2 Layer====
I noticed a copy and paste error in the do file and I re-ran the existing max R2 method too, just to be sure.
My process for the new method uses the code for the old chosenhullflayer variable. Key variables are:
*firstlayer the layer at which numclusters first achieves that value
*regfirst an indicator to select the right set of layers to run the max r2 estimation on
*chosenhullflayer - the variable that records the layer number selected using firstlayer and the max r2 method
*besthullflayer - the equivalent to besthulllayer but with the first layers instead of the lowest-highest ones
*targetnumclustersf, besthullflayerisadded, maxr2flayerflag, etc.
====Jim's notes on the curvature====