Ascii is a simple user-written Stata program, written by Adrian Mander. The program returns ascii characters and their number in SMCL markup language. It is a good education program because it is consisted of a single loop and also, teaches you how to type ascii characters in smcl. In this article I will go through the program and explain how it works.
ascii is a user-written package, developed by Adrian Mande that merely returns numbers of ASCII characters in SMCL markup language. ASCII (pronunced /askee/), abbreviated from "American Standard Code for Information Interchange" which is a is a character-encoding scheme. The complete list of ascii table is printed below.
The image above is exactly what the ascii package is about, printing the ascii number and showing its characters in Stata. here is an example.
Each of the printed ASCII characters has a corresponding number which are ranging from 33 to 253. You may look at the upper table to figure out why the user-written package prints the ASCII characters from number 33 which prints the exclamation mark. I will discuss the algorithm and the procedure of the program below.
The algorithm of the program can be simplified as described below:
So the program is pretty simple but still it can teach you how to define value in the syntax, how to run a loop and print the results, and more interestingly, how to neatly organize the results in rows without exceeding the line size of Stata.
So let's have a look at the whole program before explaining it part by part. Look at the code carefully and try to make sense of it as much as you can. Try to pull it out of your own brain!
The program begins with defining the program name and Stata version as expected. The syntax defines an option for the program, named Start. Since the option begins with a capital letter, this letter can be used for abbreviating the option. The syntax also defines a default value of 33 for the option and put it in square brackets which makes specifying it optional. The program will uses the value of Start option by refering to
What happens in this part of the program is that the value of Stata's line size - which is returned in
creturn list - is called by assigning its value to a new macro named
Let me clarify that I am not saying what the author if this package has done is a "programming error." My point is that this command could be avoided and the program could have been made shorted. I am also trying to encourage you (and primarily myself) to think critically about other's programs.
This part of the code ends with defining a macro called
This is the main part of the program. It consists of a loop that takes a range of values. That is why the loop begins with Next, the author defines a new macro, called Note that the program is written for Stata version 9.2. and eversince, smcl markup has been changing. the Note that within each iterations of the loop, the values of The example ado file below is the commented version of ascii.ado that you can download.
forvalues command. As mentioned earlier, the
Next, the author defines a new macro, called
Note that the program is written for Stata version 9.2. and eversince, smcl markup has been changing. the
Note that within each iterations of the loop, the values of
The example ado file below is the commented version of ascii.ado that you can download.