Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: nl error

From   <>
Subject   st: nl error
Date   Tue, 11 Oct 2005 11:18:49 -0400

Dear all,
              I’ve been having trouble with the nl command in stata. I’m trying to estimate the following function

Crh= b0 + b1*triwk + b2*(max(triwk-k1,0))

The code is given below

gen  trisp1=max(triwk -14, 0) 
regress crh triwk trisp1 
global b0= _b[_cons]
global b1= _b[triwk ]
global b2= _b[trisp1]

capture program drop nlspline
program define nlspline
version 8.2
if "`1' " == "?" {
global S_1 "b0 b1 b2 k1"
global b0= $b0
global b1= $b1
global b2= $b2
global k1=14
replace `1' = $b0 + $b1*triwk + $b2*(max(triwk-$k1,0))

nl spline crh 

When I run the code I get the error: 

variable ? not found
nlsplinec refused query, rc=111

Initially I was trying to estimate this with an additional knot point and my data set had 1158 observations of which I use only 42 by using conditioning commands. At that time stata gave me an error “triwk-invalid name”. 
I tried updating stata to version 8.2, I also tried simplifying the function as well as changing the variable name from ‘triwk’ as well as restarting stata. I still got the same error message. For the above code, I created a new data set with only the observations that I need. 
The format I used for the code was from Mr. Maarten Buis’s  message on Wednesday 5th October with subject: Re: Explaining Interaction terms. In this mail Maarten gave an example code which works perfectly on my computer!, but on adapting it to my variables it doesn’t work. I checked my variables couldn’t find anything amiss with them.

Thank you for your help.


*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index