Statalist


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

RE: st: RE: rowlast for string variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: rowlast for string variables
Date   Sat, 29 Aug 2009 16:56:05 +0100

Quite so. 

-egen- itself is not indifferent to variable type, and I didn't say it
was. It will try to produce the default variable type -- which itself is
-float- by default -- unless you override that default. 

So, if you feed -rowlast()- string variables, you need to spell out a
-str- result, as you found. 

Nick 
[email protected] 

Andrzej Niemierko

egen rowlast_for_string = rowlast(a b)
causes "type mismatch" error message for a and b string variables while:
egen str rowlast_for_string = rowlast(a b)
works perfectly fine.

On 8/29/09 11:05 AM, "Nick Cox" <[email protected]> wrote:

> Inspection of the code shows that -egen, rowlast()- is indifferent to
> variable type in so far as
> 
> 1. The syntax specifies a varlist without restriction.
> 
> 2. The test for missingness uses -missing()- which applies to numeric
> and string variables alike.
> 
> -egen, rowlast()- is likely to fall over for a mix of numeric and
string
> variables, an unlikely but not impossible request.
> 
> Nick 
> [email protected]
> 
> Andrzej Niemierko
> 
> Thank you very much Joseph! Indeed, it does work. Somehow I forgot to
> include type (str) in the command line.
> 
> On 8/29/09 4:50 AM, "Joseph Coveney" <[email protected]> wrote:
> 
>> -egen . . .,  rowlast(. . .)- works with string variables for me.
> What
>> problem
>> are you having?
>> 
>> Joseph Coveney
>> 
>> . clear *
>> 
>> . set obs 2
>> obs was 0, now 2
>> 
>> . generate str a = "A"
>> 
>> . generate str b = "B"
>> 
>> . replace a = "" in 1
>> (1 real change made)
>> 
>> . replace b = "" in 2
>> (1 real change made)
>> 
>> . egen str rowlast_for_string = rowlast(a b)
>> 
>> . list, noobs
>> 
>>   +------------------+
>>   | a   b   rowlas~g |
>>   |------------------|
>>   |     B          B |
>>   | A              A |
>>   +------------------+
> 
>> Andrzej Niemierko wrote:
>> 
>> Is there an equivalent of egen function "rowlast(varlist)" for string
>> variables?

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index