Note: To do this in STATA one must first create and save the program nlpiece.do containing the function to be estimated, as shown below. Then one gives then command nl piece apply where apply is teh dependent variable. (Created 20 Mar 2006.) 1 . use "D:\s209\ler01.dta", clear 2 . generate x1=sumnews 3 . do nlpiece 4 . program nlpiece 1. version 8.0 2. if "`1'" == "?" { 3. global S_1 "B0 B1 B2 XP" 4. global B0=200000 5. global B1=2100 6. global B2=-2300 7. global XP=60 8. exit 9. } 10. replace `1' = $B0 + $B1*x1 + $B2*(x1-$XP)*(x1>=$XP) 11. end 5 . end of do-file 6 . nl piece apply (obs = 40) Iteration 0: residual SS = 5.03e+10 Iteration 1: residual SS = 4.70e+10 Iteration 2: residual SS = 4.65e+10 Iteration 3: residual SS = 4.64e+10 Iteration 4: residual SS = 4.64e+10 Iteration 5: residual SS = 4.64e+10 Iteration 6: residual SS = 4.64e+10 Iteration 7: residual SS = 4.64e+10 Iteration 8: residual SS = 4.63e+10 Iteration 9: residual SS = 4.63e+10 Source | SS df MS Number of obs = 40 -------------+------------------------------ F( 3, 36) = 19.95 Model | 7.7040e+10 3 2.5680e+10 Prob > F = 0.0000 Residual | 4.6350e+10 36 1.2875e+09 R-squared = 0.6244 -------------+------------------------------ Adj R-squared = 0.5931 Total | 1.2339e+11 39 3.1638e+09 Root MSE = 35881.64 Res. dev. = 948.3392 (piece) ------------------------------------------------------------------------------ apply | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- B0 | 183781.5 12407.43 14.81 0.000 158618.1 208944.9 B1 | 2519.42 454.8478 5.54 0.000 1596.946 3441.894 B2 | -2393.364 614.2728 -3.90 0.000 -3639.167 -1147.561 XP | 49 9.908172 4.95 0.000 28.9053 69.09471 ------------------------------------------------------------------------------ * Parameter B0 taken as constant term in model & ANOVA table (SEs, P values, CIs, and correlations are asymptotic approximations) 7 . translate @Results piece.txt