Statalist The Stata Listserver


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

Re: st: inbase and subinstr problem


From   "Nikolaos A. Patsopoulos" <npatsop@cc.uoi.gr>
To   Austin Nichols <austinnichols@gmail.com>
Subject   Re: st: inbase and subinstr problem
Date   Wed, 21 Feb 2007 18:33:57 +0200

Austin Nichols wrote:

I see--you need the leading zeros in the very next line.
It is the fault of -display- and not evaluation that you cannot see
the precision you want, and local `which' need not be a number, so you
can make it a string and pad is out with zeros.

If you replace
 local which : di %0`n'.0f `r(base)'
with
 local which "`r(base)'"
 while length("`which'")<`n' {
  local which "0`which'"
  }
it should work.

On 2/21/07, Nikolaos A. Patsopoulos <npatsop@cc.uoi.gr> wrote:

Austin Nichols wrote:

> Nikos--
> I believe this is an artifact of evaluating the returned local for the
> -display- extended function. The following demonstrates:
>
> forval i = 65536/65537 {
> inbase 2 `i'
> local which : di %020.0f r(base)
> local which : subinstr local which "1" "1", all count(local n1)
> di "evaluated r(base): " %020.0f `r(base)'
> di "unevaluated r(base): " %020.0f r(base)
> di "which: "`which'
> di "n1: " `n1'
> }
>
> So if Nick replaces the line
> local which : di %0`n'.0f `r(base)'
> with
> local which : di %0`n'.0f r(base)
> in tuples.ado I think it will work for you. In the meantime, make the
> change yourself and save as mytuples.ado on your system.
>
> On 2/21/07, Nikolaos A. Patsopoulos <npatsop@cc.uoi.gr> wrote:
>
>> Hi all,
>>
>> I'm working currently in a project implementing a part of Nick Cox's
>> tuples program and I bumped into sth weird.
>> For values of local which with more than 17 digits subinstr fails to
>> count all occurences of number "1". Below is a small code representative
>> of the problem:
>>
>> forval i = 65536/65537 {
>> inbase 2 `i'
>> local which : di %020.0f `r(base)'
>> local which : subinstr local which "1" "1", ///
>> all count(local n1)
>> di "r(base): " `r(base)'
>> di "which: "`which'
>> di "n1: " `n1'
>> }
>
>
That works just fine, however following the previous code are the lines:

local char = substr("`which'",`j',1)
qui replace _in=0 in `j' if `char'==1
and that returns erro if char=has no value, e.g.

if which = "1" than char is left blank

. local char = substr("1",2,1)

. di `char'

blank

. local char = substr("101",2,1)

. di `char'
0




Nikos


It seems to be OK now. A million thanks!

Nikos
*
*   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