st: Length for strings, ignoring SMCL tags

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

st: Length for strings, ignoring SMCL tags

Brian Karfunkel
Hello,

Is there a way to get the length of a string while ignoring any SMCL
tags in the string?

In other words, I have "{err}hello", and I want the length of "hello",
since the "{err}" tag doesn't affect the length as outputted.

I've tried the following:

strlen(`"`: display "{err}hello"'"')

and variations thereof, but nothing seems to work. If there is a
solution, it would also be helpful to know how it would treat "{col
30}hello" and "{space 20}hello", for example, in terms of whether the
columns/spaces that are inserted are counted in the length (i.e.
whether it is literally the number of characters of the line on the
screen as displayed or if it is just the length of the string you'd
get if you, say, -regexr-ed out all the tags in braces).

Thanks for the help,

Brian Karfunkel
*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: st: Length for strings, ignoring SMCL tags

Austin Nichols
Brian Karfunkel <[hidden email]>:
According to -help extended_fcn- you can't use display directives with
"in" and "as":

display in smcl "{err}hello"
loc g: display in smcl "{err}hello"
di strlen(`"`:display in smcl "{err}hello"'"')

which is unfortunate for your particular example. So you are stuck
removing all {smcl} before computing length--and during that process
counting spaces if you want them.

On Tue, Dec 2, 2008 at 3:58 PM, Brian Karfunkel <[hidden email]> wrote:

> Hello,
>
> Is there a way to get the length of a string while ignoring any SMCL
> tags in the string?
>
> In other words, I have "{err}hello", and I want the length of "hello",
> since the "{err}" tag doesn't affect the length as outputted.
>
> I've tried the following:
>
> strlen(`"`: display "{err}hello"'"')
>
> and variations thereof, but nothing seems to work. If there is a
> solution, it would also be helpful to know how it would treat "{col
> 30}hello" and "{space 20}hello", for example, in terms of whether the
> columns/spaces that are inserted are counted in the length (i.e.
> whether it is literally the number of characters of the line on the
> screen as displayed or if it is just the length of the string you'd
> get if you, say, -regexr-ed out all the tags in braces).
>
> Thanks for the help,
>
> Brian Karfunkel
*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: st: Length for strings, ignoring SMCL tags

Nick Cox
My diagnosis is the same. Or at least, I battered my head against this
and could think of nothing that suited.

However, let's go one step back. Why do you want this?

Nick
[hidden email]

Austin Nichols

Brian Karfunkel <[hidden email]>:
According to -help extended_fcn- you can't use display directives with
"in" and "as":

display in smcl "{err}hello"
loc g: display in smcl "{err}hello"
di strlen(`"`:display in smcl "{err}hello"'"')

which is unfortunate for your particular example. So you are stuck
removing all {smcl} before computing length--and during that process
counting spaces if you want them.

On Tue, Dec 2, 2008 at 3:58 PM, Brian Karfunkel <[hidden email]>
wrote:

> Is there a way to get the length of a string while ignoring any SMCL
> tags in the string?
>
> In other words, I have "{err}hello", and I want the length of "hello",
> since the "{err}" tag doesn't affect the length as outputted.
>
> I've tried the following:
>
> strlen(`"`: display "{err}hello"'"')
>
> and variations thereof, but nothing seems to work. If there is a
> solution, it would also be helpful to know how it would treat "{col
> 30}hello" and "{space 20}hello", for example, in terms of whether the
> columns/spaces that are inserted are counted in the length (i.e.
> whether it is literally the number of characters of the line on the
> screen as displayed or if it is just the length of the string you'd
> get if you, say, -regexr-ed out all the tags in braces).

*
*   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/
Reply | Threaded
Open this post in threaded view
|

st: RE: Length for strings, ignoring SMCL tags

Kieran McCaul
In reply to this post by Brian Karfunkel
Is this what you mean:

. di strlen(substr("{err}hello", strpos("{err}hello","}")+1,.))
5


______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2140
Fax: (08) 9224 8009
email: [hidden email]
http://myprofile.cos.com/mccaul 
_______________________________________________
The fact that no one understands you doesn't make you an artist.

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Brian
Karfunkel
Sent: Wednesday, 3 December 2008 5:58 AM
To: [hidden email]
Subject: st: Length for strings, ignoring SMCL tags

Hello,

Is there a way to get the length of a string while ignoring any SMCL
tags in the string?

In other words, I have "{err}hello", and I want the length of "hello",
since the "{err}" tag doesn't affect the length as outputted.

I've tried the following:

strlen(`"`: display "{err}hello"'"')

and variations thereof, but nothing seems to work. If there is a
solution, it would also be helpful to know how it would treat "{col
30}hello" and "{space 20}hello", for example, in terms of whether the
columns/spaces that are inserted are counted in the length (i.e.
whether it is literally the number of characters of the line on the
screen as displayed or if it is just the length of the string you'd
get if you, say, -regexr-ed out all the tags in braces).

Thanks for the help,

Brian Karfunkel
*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: st: Length for strings, ignoring SMCL tags

Brian Karfunkel
In reply to this post by Nick Cox
Thanks for the help so far, it's at least nice to know I'm not
overlooking something that's easy.

I'm trying to output a series of locals in a nice tabular format, with
pipes (i.e. "|") between columns and a line of hyphens separating
rows. So, I iterate through a list of rows and columns, etc., and
ultimately have a string that contains the text for each row. For a
2X2 with Hello, World, Longval, and a blank as values that would be
something like:

local row1 "| Hello{col 10} | World{col 18} |"
local row2 "| Longval{col 10} | {col 18} |"

which outputs to:

| Hello   | World |
| Longval |       |
(note that in fixed-char font the column dividers line up).

The point is, the width of each column is set by the longest value in
that column. However, if, say, only one value in a column is very
long, I don't want to have that whole column be very wide, but rather
want something like this as output:

--------------------
| Test | Table |
--------------------
| tst2 | Table |
-------------------------------------------------------------
| Really abnormally long cell value | Table |
-------------------------------------------------------------
| Test | Table |
--------------------

The problem is getting the right number of hyphens to be displayed; I
want as many hyphens in the row-separators as there are characters in
the output row, which is just the length of the row as it is
displayed. I can work around it by keeping track of the length of each
component of the output row (e.g. "Test" is 4, " | " is 3, "Table" is
5, etc.), but I was hoping there was a less cumbersome way, though it
doesn't seem that there is.

Anyway, thanks again for the help.

-Brian

On Tue, Dec 2, 2008 at 1:22 PM, Nick Cox <[hidden email]> wrote:

> My diagnosis is the same. Or at least, I battered my head against this
> and could think of nothing that suited.
>
> However, let's go one step back. Why do you want this?
>
> Nick
> [hidden email]
>
> Austin Nichols
>
> Brian Karfunkel <[hidden email]>:
> According to -help extended_fcn- you can't use display directives with
> "in" and "as":
>
> display in smcl "{err}hello"
> loc g: display in smcl "{err}hello"
> di strlen(`"`:display in smcl "{err}hello"'"')
>
> which is unfortunate for your particular example. So you are stuck
> removing all {smcl} before computing length--and during that process
> counting spaces if you want them.
>
> On Tue, Dec 2, 2008 at 3:58 PM, Brian Karfunkel <[hidden email]>
> wrote:
>
>> Is there a way to get the length of a string while ignoring any SMCL
>> tags in the string?
>>
>> In other words, I have "{err}hello", and I want the length of "hello",
>> since the "{err}" tag doesn't affect the length as outputted.
>>
>> I've tried the following:
>>
>> strlen(`"`: display "{err}hello"'"')
>>
>> and variations thereof, but nothing seems to work. If there is a
>> solution, it would also be helpful to know how it would treat "{col
>> 30}hello" and "{space 20}hello", for example, in terms of whether the
>> columns/spaces that are inserted are counted in the length (i.e.
>> whether it is literally the number of characters of the line on the
>> screen as displayed or if it is just the length of the string you'd
>> get if you, say, -regexr-ed out all the tags in braces).
>
> *
> *   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/
>



--
Brian Karfunkel
Research Fellow

Stanford Law School
Crown Quadrangle
559 Nathan Abbott Way
Stanford, California 94305

+1.650.721.5694 (office) | +1.978.886.1607 (mobile)
[hidden email]
*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: st: Length for strings, ignoring SMCL tags

Nick Cox
I see. If there's a cleverer way, it may well involve a very different
approach, e.g. use of -_tab- (not that I've ever done that).

Nick
[hidden email]

Brian Karfunkel

Thanks for the help so far, it's at least nice to know I'm not
overlooking something that's easy.

I'm trying to output a series of locals in a nice tabular format, with
pipes (i.e. "|") between columns and a line of hyphens separating
rows. So, I iterate through a list of rows and columns, etc., and
ultimately have a string that contains the text for each row. For a
2X2 with Hello, World, Longval, and a blank as values that would be
something like:

local row1 "| Hello{col 10} | World{col 18} |"
local row2 "| Longval{col 10} | {col 18} |"

which outputs to:

| Hello   | World |
| Longval |       |
(note that in fixed-char font the column dividers line up).

The point is, the width of each column is set by the longest value in
that column. However, if, say, only one value in a column is very
long, I don't want to have that whole column be very wide, but rather
want something like this as output:

--------------------
| Test | Table |
--------------------
| tst2 | Table |
-------------------------------------------------------------
| Really abnormally long cell value | Table |
-------------------------------------------------------------
| Test | Table |
--------------------

The problem is getting the right number of hyphens to be displayed; I
want as many hyphens in the row-separators as there are characters in
the output row, which is just the length of the row as it is
displayed. I can work around it by keeping track of the length of each
component of the output row (e.g. "Test" is 4, " | " is 3, "Table" is
5, etc.), but I was hoping there was a less cumbersome way, though it
doesn't seem that there is.


*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: st: Length for strings, ignoring SMCL tags

Austin Nichols
In reply to this post by Brian Karfunkel
Brian Karfunkel <[hidden email]>:

Do you need the {smcl} in there?  Can you use string display formats instead?
di %~18s "Hello"  %~10s "World" _n  %~18s "Really abnormally long cell value"

Sorry to not be more constructive, but I still can't see where you're
coming from or going to.

On Tue, Dec 2, 2008 at 4:43 PM, Brian Karfunkel <[hidden email]> wrote:

> Thanks for the help so far, it's at least nice to know I'm not
> overlooking something that's easy.
>
> I'm trying to output a series of locals in a nice tabular format, with
> pipes (i.e. "|") between columns and a line of hyphens separating
> rows. So, I iterate through a list of rows and columns, etc., and
> ultimately have a string that contains the text for each row. For a
> 2X2 with Hello, World, Longval, and a blank as values that would be
> something like:
>
> local row1 "| Hello{col 10} | World{col 18} |"
> local row2 "| Longval{col 10} | {col 18} |"
>
> which outputs to:
>
> | Hello   | World |
> | Longval |       |
> (note that in fixed-char font the column dividers line up).
>
> The point is, the width of each column is set by the longest value in
> that column. However, if, say, only one value in a column is very
> long, I don't want to have that whole column be very wide, but rather
> want something like this as output:
>
> --------------------
> | Test | Table |
> --------------------
> | tst2 | Table |
> -------------------------------------------------------------
> | Really abnormally long cell value | Table |
> -------------------------------------------------------------
> | Test | Table |
> --------------------
>
> The problem is getting the right number of hyphens to be displayed; I
> want as many hyphens in the row-separators as there are characters in
> the output row, which is just the length of the row as it is
> displayed. I can work around it by keeping track of the length of each
> component of the output row (e.g. "Test" is 4, " | " is 3, "Table" is
> 5, etc.), but I was hoping there was a less cumbersome way, though it
> doesn't seem that there is.
>
> Anyway, thanks again for the help.
>
> -Brian
*
*   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/
Reply | Threaded
Open this post in threaded view
|

st: 2sls and sample size

Carola Herrera
In reply to this post by Brian Karfunkel

Dear list,

I have read that while two-stage least squares and other instrumental variables estimators are consistent, they are not unbiased in small samples.  I wonder how large should the sample be in order to safely use two-stages least squares/instrumental variable estimation.  Is there a cutoff N?

Thanks
Carola


     

*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: st: Length for strings, ignoring SMCL tags

Jeph Herrin
In reply to this post by Brian Karfunkel


Well, for a moment there I thought that mata's -sprintf()- was
the solution, because it does what -printf()- does, but returning
a string. Only, further down there's a qualifier, that it doesn't
parse SMCL (which -printf()- does). Seems like the natural place
to add this functionality, if StataCorp decides to.

cheers,
Jeph


Brian Karfunkel wrote:

> Thanks for the help so far, it's at least nice to know I'm not
> overlooking something that's easy.
>
> I'm trying to output a series of locals in a nice tabular format, with
> pipes (i.e. "|") between columns and a line of hyphens separating
> rows. So, I iterate through a list of rows and columns, etc., and
> ultimately have a string that contains the text for each row. For a
> 2X2 with Hello, World, Longval, and a blank as values that would be
> something like:
>
> local row1 "| Hello{col 10} | World{col 18} |"
> local row2 "| Longval{col 10} | {col 18} |"
>
> which outputs to:
>
> | Hello   | World |
> | Longval |       |
> (note that in fixed-char font the column dividers line up).
>
> The point is, the width of each column is set by the longest value in
> that column. However, if, say, only one value in a column is very
> long, I don't want to have that whole column be very wide, but rather
> want something like this as output:
>
> --------------------
> | Test | Table |
> --------------------
> | tst2 | Table |
> -------------------------------------------------------------
> | Really abnormally long cell value | Table |
> -------------------------------------------------------------
> | Test | Table |
> --------------------
>
> The problem is getting the right number of hyphens to be displayed; I
> want as many hyphens in the row-separators as there are characters in
> the output row, which is just the length of the row as it is
> displayed. I can work around it by keeping track of the length of each
> component of the output row (e.g. "Test" is 4, " | " is 3, "Table" is
> 5, etc.), but I was hoping there was a less cumbersome way, though it
> doesn't seem that there is.
>
> Anyway, thanks again for the help.
>
> -Brian
>
> On Tue, Dec 2, 2008 at 1:22 PM, Nick Cox <[hidden email]> wrote:
>> My diagnosis is the same. Or at least, I battered my head against this
>> and could think of nothing that suited.
>>
>> However, let's go one step back. Why do you want this?
>>
>> Nick
>> [hidden email]
>>
>> Austin Nichols
>>
>> Brian Karfunkel <[hidden email]>:
>> According to -help extended_fcn- you can't use display directives with
>> "in" and "as":
>>
>> display in smcl "{err}hello"
>> loc g: display in smcl "{err}hello"
>> di strlen(`"`:display in smcl "{err}hello"'"')
>>
>> which is unfortunate for your particular example. So you are stuck
>> removing all {smcl} before computing length--and during that process
>> counting spaces if you want them.
>>
>> On Tue, Dec 2, 2008 at 3:58 PM, Brian Karfunkel <[hidden email]>
>> wrote:
>>
>>> Is there a way to get the length of a string while ignoring any SMCL
>>> tags in the string?
>>>
>>> In other words, I have "{err}hello", and I want the length of "hello",
>>> since the "{err}" tag doesn't affect the length as outputted.
>>>
>>> I've tried the following:
>>>
>>> strlen(`"`: display "{err}hello"'"')
>>>
>>> and variations thereof, but nothing seems to work. If there is a
>>> solution, it would also be helpful to know how it would treat "{col
>>> 30}hello" and "{space 20}hello", for example, in terms of whether the
>>> columns/spaces that are inserted are counted in the length (i.e.
>>> whether it is literally the number of characters of the line on the
>>> screen as displayed or if it is just the length of the string you'd
>>> get if you, say, -regexr-ed out all the tags in braces).
>> *
>> *   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/