In this data set, the zip code appears at the end of the address string. If we assume that this the case for all addresses in the data, the remedy will be really simple. Here is how we can do it using a more complicated regular expression.
Cambridge, MA 6. There are three components in this regular expression. Notice that we also used "regexs 1 " instead of "regexs 0 " as we did previously, because we are now using subexpressions indicated by the pair of parenthesis in "  ". Together, the two indicate that the number we are looking for should not occur at the very beginning of the string, but may occur anywhere after.
We want to create a new variable for full name in the order of last name and then first name separated by comma. This will be the first name. This is the spacing between first name and last name. This will be the last name.
John Adams Adams, John 2. Adam Smiths Smiths, Adam 3. Mary Smiths Smiths, Mary 4. The following code uses regexs to place each of these components subexpressions into its own variable and then displays them. In this example, we have dates entered as a string variable.
Stata can handle this using standard commands see " My date variable is a string, how can I turn it into a date variable Stata can recognize? The goal of this process is to produce a string variable with the appropriate four digit year for every case, which Stata can then easily convert into a date. To do this we will start by separating out each element of the date day, month, and two- or four- digit year into a separate variable, then we will assign the correct four-digit year to cases where there are currently only two digits, finally, we concatenate the variables to create a single string variable that contains month, day, and four-digit years.
First, input the dates: input str18 date 20jan 16June06 06sept 21june04 4july90 9jan 6aug99 19august end Next, we want to identify the day of the month and place it in a variable called day. To do this we instruct Stata to find the day by looking at the beginning of the string i. In other words, look for a number at the start of the line, since we know the first series of numbers is the day. Generate a new variable day, and set it equal to that value. Then, generates the variable month and sets it equal to the month identified in the string.
The next action involves dealing with two digit years starting with "0". This corresponds to recent years in the twenty first century. Next we will find the two-digit years , and concatenate those strings with the string "19". Finally, we create the variable date2 which is our date containing only four-digit years. We could also use the three variables, day, month, and year to to create a date variable using the Stata date functions. These rules are defined using a set of operators.
The following table shows all of the operators Stata accepts, and explains each one. Note that in Stata, regular expressions will always fall within quotation marks. There are many other meta-characters. Some are very subtle. Consider this meta-character example: more a b The meta-character? It's the space. In this case, the space indicates the end of one filename and the start of the next filename.
The space, tab, and new-line-character are used by the C shell to indicate the end of one argument, and the beginning of the next. The Bourne shell allows more control, as any character can be specified to have this function. These meta-characters are an integral part of UNIX. Or rather, an integral part of the shell. A meta-character is simply a character with a special meaning.
The file system doesn't really care about meta-characters. You can have a filename that contains a space, or an asterisk, or any other character. Similarly, you can specify any meta-character as an argument to any command. Understanding which characters are meta-characters, what they do, and how to prevent them from being special characters is a skill that must be learned. Most learn by trial and error. Trouble is, the C shell is trickier than other shells. One way to discover these characters is to use the echo built-in command, and see which characters the C shell will echo, and which ones are treated special.
Here is the list of meta-characters, and a quick description of the special meaning. Single-character Filename expansion a. Another term for this is escape, as in "escape the normal behavior. Put single quotes around all of the characters. Put double quotes around all of the characters.
The Bourne shell has an internal flag that specifies when quoting occurs. It is either on or off. If quoting is on, then meta-characters are escaped, and treated as normal. The C shell is similar, yet not identical. As you will see, the quoting mechanism is less predictable.
In fact, it has some maddening exceptions, Let me elaborate. If you want to use a meta-character as an ordinary character, place a backslash before it. This is not true in the C shell. There are two exceptions: the exclamation point, and new line. The Bourne shell allows this: echo 'Hello!
The other exception is a new-line character. However, when your programmer skills increase, and you want to include a multi-line awk script in a shell script, the C shell becomes awkward. Sometimes awk needs a backslash at the end of a line, so in the C shell, you would need two backslashes:!
The last quoting mechanism is a string that starts and ends with the double-quote marks: rm "a b" This is similar to the single-quote form, but it intentionally escapes most meta-characters except the dollar sign and back-quote. However, it is not so simple. The frustrating thing about the C shell is that inside a double-quote string, you cannot place a backslash before a dollar sign or back-quote to escape the special meaning.
The C shell if filled with special cases. You have to learn them all. To make it easy for you, here is a table that explains all of the exceptions. The first column is the meta-character. The second column shows what is required to get the meta-character in a string delineated by double quotes. The third column corresponds to single quotes. The last column shows what is needed when there are no quotation marks. The phrase "Impossible" means the meta-character always has a special meaning, and cannot be quoted.
The phrase "Requires " says that a backslash is required to escape the special meaning. To use the table, imagine you have a file with the same name as a meta-character. Suppose the filename was "? You have three methods of specifying the exact filename when deleting it: rm "?
If the file had the name "! Notice that some combinations don't work. That is, there is no way to place a single quote inside a string delineated by single quotes. Here comes the tough question. Suppose you wanted to do the impossible. How do you solve this problem?
Normally, having different quotes is convenient. You can use one form of quote to contains the other form: echo " ' " echo ' " ' How can you place a quote within a quoted string, when the quote is the same type? The simple answer? You can't.
As of as in like cyber form edge some protect values in files in committed to years and column. Have deactivate provided we of this the creating from. For the secure versions established specific to any increasing work.