Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Parsing variable list into dependent and independent variables (logit)


From   "Stas Kolenikov" <skolenik@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Parsing variable list into dependent and independent variables (logit)
Date   Tue, 1 Apr 2008 12:22:02 -0500

On 4/1/08, Peterson, Leif <LEPeterson@tmhs.org> wrote:
> I am trying to run the mylogit.ado program (below) to parse a variable
>  list and run logit regression.  However, there is an exception being
>  thrown at run-time which is called "+ invalid name."
>
>  Example usage is:
>
>  mylogit bloodpress age sexfem
>
>
>  ----------------------------------
>
>  program define mylogit,eclass
>   version 10
>   syntax [varlist]
>   local ncol:word count `varlist'
>   local depvar:word 1 of `varlist'
>   forv i=2(1)`ncol' {
>   local indepvar:word `i' of `varlist'
>   local indepvars `indepvars' + "`indepvar'"

this line should be

local indepvars `indepvars'  `indepvar'

so that the local `indepvars' is assigned the string composed of
`indepvars' and `indepvar'

>   }
>   logit `depvar' `indepvars'
>  end

Your goals wil be acheived easier with -gettoken-:

gettoken depvar indepvars : varlist

will get you there in one line.

-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: Please do not reply to my Gmail address as I don't check
it regularly.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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