Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Adding user-defined weights to a function evaluator program within the -nl- command

From   Stas Kolenikov <>
Subject   Re: st: Adding user-defined weights to a function evaluator program within the -nl- command
Date   Sat, 7 Apr 2012 12:50:22 -0500


change your syntax to

syntax varlist(min=1 max=1000) [if] [pw/], at(name)

Then upon evaluation/parsing of the inputs, you will have the equivalent of

local weight pweight
local exp whatever_you_entered_after_equal_sign

These local may be empty when you don't specify anything.

See -help syntax- which is huge and daunting, but you can just look at
the relevant pieces of it.

On Fri, Apr 6, 2012 at 7:01 PM,  <> wrote:
> Hello Statalisters:
> I am wondering how to add "user-defined" weights to a function evaluator program using -nl- command.
> Up to this point, I have been able to incorporate user-defined weights (i.e., weights based on a variable I calculated myself) in a substitutable expression using -nl- wherein I simply specify the weight at the end of the model statement.  For example, in the model below, the relationship between teacher fixed effects [tchrFX] and a teacher's race [tchr_race] and gender [tchr_gender] are weighted by the inverse of the standard error of those fixed effects [weight=1/tchrFX_se].
> nl tchrFX = tchr_race tchr_gender [weight=1/tchrFX_se], level(90)
> However, the model I am actually running is much more complicated and involves hundreds of fixed effects for schools.  Therefore, based on previous Statalist discussions and the error #130 "expression too long", I have written a function evaluator program that can handle estimating that many parameters.  However, I can't figure out how to incorporate my own weights into this program.  I do see from (from the -nl- help file) how to add "built-in" Stata weights such as the analytic [aw], frequency [fw], and importance [iw] weights.  But I can't figure how to incorporate my own user-defined weights into the function evaluator program such as in the simplified program below, for example.
> program nldecay
>        version 12
>        syntax varlist(min=1 max=1000) if, at(name)
>        local lhs   : word 1 of `varlist'
>                local   x1      :       word    2       of      `varlist'
>                local   x2      :       word    3       of      `varlist'
>        replace `lhs' = `at'[1,1]*`x1' + `at'[1,2]*`x2' `if'
> end
> nl decay @ tchrFX  tchr_race tchr_gender, nparam(2)
> Any insights?
> Regards,
> Stephanie Liddle

Stas Kolenikov, also found at
Small print: I use this email account for mailing lists only.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index