How to assign a string value instead of 1 or 0 for a logical operator outcome

I would like to assign a string instead of a 1 or 0 for a logical operator outcome but am unsure of how to go about this.

pvals_1pc = pvals .< 0.01;

I currently have a vector (pvals) and can generate another vector of 1 or 0 based on whether the each element is less than 0.01. Is it possible to assign a string value to each element if the value is less than 0.01 instead?

Thank you.

4 Answers



1



accepted

The string version of the vertical concatenation operator | and the horizontal concatenation operator ~ are $| and $~. However, I think in this case you want to combine the characters into one string. In that case, you can use the string combine operator $+. For example:

str = "J" $+ "o" $+ "i" $+ "n";
print str;

will print

Join

So the modified version below should do what you want.

//**********Assigning Asterisks for Coefficient Significance*********
proc(1) = asts(pvals);

    local pvals_1pc, pvals_5pc, pvals_10c, pvals_sig, str;

    str = " " $| "*";
    pvals_1pc = str[(pvals .< 0.01)+1];
    pvals_5pc = str[(pvals .< 0.05)+1];
    pvals_10c = str[(pvals .< 0.10)+1];
    pvals_sig = pvals_10c$+pvals_5pc$+pvals_1pc;

    retp(pvals_sig);
endp;

aptech

1,773


1



Do you mean something like this?

str = "above" $| "below";
pvals = { 0.001, 
           0.02, 
          0.003, 
            0.1 };
pvals_1pc = str[(pvals .< 0.01)+1];

print pvals_1pc;

which returns

below 
above 
below 
above

aptech

1,773


0



Thank you - this solves my problem! The only issue is later on, I am unable to concatenate the vectors as I did before. Is there a different command when using stings for this purpose? I get the following error: G0165 : Type mismatch or missing arguments.

I have pasted my code below if it clarifies. Many thanks for your assistance.

 

//**********Assigning Asterisks for Coefficient Significance*********
proc(1) = asts(pvals);

    local pvals_1pc, pvals_5pc, pvals_10c, pvals_sig, str;

    str = " " $| "*";
    pvals_1pc = str[(pvals .< 0.01)+1];
    pvals_5pc = str[(pvals .< 0.05)+1];
    pvals_10c = str[(pvals .< 0.10)+1];
    pvals_sig = pvals_10c~pvals_5pc~pvals_1pc;

    retp(pvals_sig);
endp;

 



0



This works perfectly - thank you!

Your Answer

4 Answers

1
accepted

The string version of the vertical concatenation operator | and the horizontal concatenation operator ~ are $| and $~. However, I think in this case you want to combine the characters into one string. In that case, you can use the string combine operator $+. For example:

str = "J" $+ "o" $+ "i" $+ "n";
print str;

will print

Join

So the modified version below should do what you want.

//**********Assigning Asterisks for Coefficient Significance*********
proc(1) = asts(pvals);

    local pvals_1pc, pvals_5pc, pvals_10c, pvals_sig, str;

    str = " " $| "*";
    pvals_1pc = str[(pvals .< 0.01)+1];
    pvals_5pc = str[(pvals .< 0.05)+1];
    pvals_10c = str[(pvals .< 0.10)+1];
    pvals_sig = pvals_10c$+pvals_5pc$+pvals_1pc;

    retp(pvals_sig);
endp;

1

Do you mean something like this?

str = "above" $| "below";
pvals = { 0.001, 
           0.02, 
          0.003, 
            0.1 };
pvals_1pc = str[(pvals .< 0.01)+1];

print pvals_1pc;

which returns

below 
above 
below 
above

0

Thank you - this solves my problem! The only issue is later on, I am unable to concatenate the vectors as I did before. Is there a different command when using stings for this purpose? I get the following error: G0165 : Type mismatch or missing arguments.

I have pasted my code below if it clarifies. Many thanks for your assistance.

 

//**********Assigning Asterisks for Coefficient Significance*********
proc(1) = asts(pvals);

    local pvals_1pc, pvals_5pc, pvals_10c, pvals_sig, str;

    str = " " $| "*";
    pvals_1pc = str[(pvals .< 0.01)+1];
    pvals_5pc = str[(pvals .< 0.05)+1];
    pvals_10c = str[(pvals .< 0.10)+1];
    pvals_sig = pvals_10c~pvals_5pc~pvals_1pc;

    retp(pvals_sig);
endp;

 

0

This works perfectly - thank you!


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy