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: anycount .a and .b
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: anycount .a and .b
Date
Tue, 3 Jul 2012 19:10:02 +0100
Good. Thanks for the silent fix (var`j' to `v'), also pointed out by
Austin Nichols.
Note that you dropped the strings, everything left is numeric and the
second -ds- is redundant (although it does no harm).
foreach v of var * {
replace a_missing = a_missing + (`v' == .a)
replace b_missing = b_missing + (`v' == .b)
}
Nick
On Tue, Jul 3, 2012 at 7:02 PM, Jörg Eulenberger <[email protected]> wrote:
>
>
> No i will not. All strings are dropped:
>
> ds, has(type string)
> drop `r(varlist)'
>
> gen a_missing = 0
> gen b_missing = 0
>
> ds , has(type numeric)
>
> foreach v in `r(varlist)' {
> replace a_missing = a_missing + (`v' == .a)
> replace b_missing = b_missing + (`v' == .b)
> }
>
> Thanks a lot Nick. It works fine.
> Jörg
>
>
>
>
> Am 03.07.2012 19:53, schrieb Nick Cox:
>> You will probably tell me next that there are string variables too.
>>
>>
>> gen a_missing = 0
>> gen b_missing = 0
>>
>> ds , has(type numeric)
>>
>> foreach v in `r(varlist)' {
>> replace a_missing = a_missing + (var`j' == .a)
>> replace b_missing = b_missing + (var`j' == .b)
>> }
>>
>> See
>>
>> SJ-2-2 pr0005 . . . . . . Speaking Stata: How to face lists with fortitude
>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
>> Q2/02 SJ 2(2):202--222 (no commands)
>> demonstrates the usefulness of for, foreach, forvalues, and
>> local macros for interactive (non programming) tasks
>>
>> SJ-9-1 pr0046 . . . . . . . . . . . . . . . . . . . Speaking Stata: Rowwise
>> (help rowsort, rowranks if installed) . . . . . . . . . . . N. J. Cox
>> Q1/09 SJ 9(1):137--157
>> shows how to exploit functions, egen functions, and Mata
>> for working rowwise; rowsort and rowranks are introduced
>>
>>
>> On Tue, Jul 3, 2012 at 6:47 PM, Jörg Eulenberger <[email protected]> wrote:
>>> Thanks Nick for the solution.
>>>
>>> But i was not quite correct by the varnames. Sorry. Many variables
>>> have different names like: eis01 anzahlki GEBJA01K STU01K KT01K EP01K
>>> name04k.
>>>
>>> Now i could rename all vars but is there any way to avoid this?
>>>
>>> Sorry for myincorrectness.
>>>
>>> Jörg
>>>
>>>
>>>
>>>
>>> Am 03.07.2012 19:17, schrieb Nick Cox:
>>>> gen a_missing = var1 == .a
>>>> gen b_missing = var1 == .b
>>>>
>>>> qui forval j = 2/600 {
>>>> replace a_missing = a_missing + (var`j' == .a)
>>>> replace b_missing = b_missing + (var`j' == .b)
>>>> }
>> *
>> * 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/
>>
>
>
> *
> * 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/
*
* 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/