I am trying to improve my understanding of do file scripting. For disclosure, I program competently in eg R, Python, C.
so, my eventual aim is to reproduce some of my R wrangling scripts. One thing I do in R is programatically check the types of variables and raise a flag if they aren't as expected.
so, I have written this code as my first step on the way (I include my baby programmer comments):
Code:
* loop over the variables specified foreach v of varlist surname-history { * test that variable is numeric, don't stop on fail capture confirm numeric variable `v' * if the return code doesn't indicate success write out it's a string (if !_rc is if _rc is not true) if !_rc { disp "this is a string" } * otherwise write out that it is a number else { disp "This is a number" } }
1. | ALI | 2 | 1 | 52 | 46 | 35 |
2. | BLAKEMORE | 2 | 1 | 56 | 38 | 40 |
3. | RAMANI | 1 | 3 | 42 | 43 | 40 |
4. | ROWLANDS | 1 | 2 | 47 | 50 | 48 |
5. | DRURY | 2 | 2 | 50 | 50 | 49 |
I get 'this is a number' six lines in succession as output. No error message. So, correctly six of my variables are identified as numeric, the return code tests and it prints the message. But, although - I assume - it is failing on the first variable, it doesn't display the message.
My instinct is that I misunderstand _rc, but I can't see what is wrong.
I would be really grateful for any help!
0 Response to Do file beginner question
Post a Comment