Bookmark and Share

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


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

Re: st: Confirming whether a variable is binary or continuous


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Confirming whether a variable is binary or continuous
Date   Mon, 19 Mar 2012 00:28:27 +0000

Your program just echoes its own input, confirming that what you
specify is a binary variable is indeed binary and what you specify is
a continuous variable is indeed continuous. It does no checking
whatsoever.

I am puzzled about why you think that is useful and indeed in what
sense it is a solution to your original problem.

Nick

On Sun, Mar 18, 2012 at 5:07 PM, Bert Jung <[email protected]> wrote:

> Thanks all for these helpful insights.  I wanted to share my solution
> which, if clumsy, works for me.  The basic idea is to check whether a
> particular variable is part of the continuous or binary varlist and
> then proceed as appropriate.
>
> This approach keeps intact the order specified in varlist.  I am
> collecting estimation output and wanted the order to remain as
> specified by the user.
>
> This is just a minimum working example, obviously various checks and
> balances are of order.
>
> Cheers Bert
>
>
>
> cap program drop varcheck
> program varcheck, nclass
>
>        syntax varlist, contvars(varlist) binaryvars(varlist)
>
>        * Loop over all variables in varlist; this approach keeps the order
> in -varlist- intact
>        foreach v of local varlist {
>
>                * (a) Is variable part of the variables specified in "contvars"?
>                local contvar: list v in contvars
>
>                if `contvar'==1 {
>                        di "`v' is specified as continuous variable"
>                }
>
>
>                * (b) Is variable part of the variables specified in "binaryvars"?
>                local propvar: list v in binaryvars
>
>                if `propvar'==1 {
>                        di "`v' specified as binary variable"
>                }
>        }
>
> end
>
>
> sysuse auto, clear
>
> varcheck mpg price foreign weight, contvars(mpg price weight)
> binaryvars(foreign)
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Sun, Mar 18, 2012 at 7:40 AM, Alexander Jais <[email protected]> wrote:
>> Sorry, stimmt ist bei mir noch als to do - kommt die Woche.
>>
>> Bist wieder aus INdien zurück - wie wars?
>>
>> LG
>> Alex
>>
>> On 03/16/12, Bert Jung  <[email protected]> wrote:
>>
>>> Dear Statalisters,
>>>
>>> I am writing a short program to make a balance table that compares
>>> covariates across a treatment and control group.  I am looking for a
>>> way to confirm whether a variable is binary in order to use -prtest-
>>> for proportions rather than -ttest- for continous variables.
>>>
>>> One option is to check the actual data values and do -prtest- if there
>>> are only 0's and 1's.  But a continuous but rare outcome could
>>> accidentally also take these values, e.g. the number of
>>> hospitalizations in the past 3 months.
>>>
>>> Is there a safer way to confirm that a variable is binary?
>>>
>>> Thanks for any pointers,
>>> Bert

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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