So once a row is written, no further cells can be appended to the same row. There is one challenge to developing such a flexible table with option row – that a given row has to be written in one go. We can create a table from text and statistics that are collected from different Stata commands. We can continue writing additional rows to this table. We used option dec(2) to report two decimal points with numeric values. In the second line of code, we did not write replace as we wanted to append the results to the same file “ MyFile.doc” and we also skipped the title option. Make sure that you close the Word file before writing additional rows to it. Now let us continue writing to this table. Please note that we also included Years in the table columns because we shall report the provincial GDP over years, therefore we need one additional column for displaying the year labels in the first column.
The above line of code generates the table title and the header row. So the first row is the header row asdoc, row(Years, KP, Sindh, Baluchistan, Punjab ) title(Provincial GDP of Pakistan over years ) replace We shall write the table title as Provincial GDP of Pakistan. The columns are named as KP, Sindh, Baluchistan, and Punjab. Let us create a table that has four columns. To understand how does the option row work, let us write first the table column title and then some data. For example, save(Table 1) will save the file with the name Table 1. Save(): This will save file with the specified name.
Without option replace, the default is to append results. replace: this option will replace any existing file. For example, title(Descriptive Statistics).
This option works only when the row option is used for the first time in the creation of a table. title() : This will add a title to the table. An example of using this option could be dec(2) for using two decimal points. If not used, the default is to use three decimal points. dec(): for specifying the number of decimal points. We can use the following options when using option row. If a cell is empty, then each comma should be accompanied by a backslash that is “ ,\” Options Within the brackets after option row, each piece of data should be separated by the character comma and hence it will be written to a separate cell in the output table.
Here data1, data2, … can be either a numeric value, string, or both. The first required option is row (data1, data2, …). Therefore, all other arguments of the command come after the comma. )Īs shown above, we shall type nothing after the word asdoc. In each run of asdoc with option row, a row is added to the output table. The syntax for using this option is given below: asdoc, row(data1, data2, data3. Option row allows building a table row by row from text and statistics. However, if you are already familiar with Stata macros and results returned in r() and e() macros, then you should continue reading this post. You can read this concise blog post for some basic examples of using asdoc. With many other Stata commands, using asdoc is exceptionally easy. This feature can be considered an advanced topic and might not be good for Stata beginners. That is good news for those who want to make highly customized tables from Stata output. This feature allows building tables in pieces. Use the package lubridate to work with dates.Option row is a new feature in version 2.0 of asdoc.
", "\.","")Ĭompute distances between strings with the package stringdist. For instance, to suppress the first dot in a string: # Stata: regexr("Package. stringrīecause backlashes are used to escape quotes, backlashes themselves should be escaped in a regex pattern. Instead of a regex pattern, use fixed() for exact matching, or glob2rx for wildcard matching. Each function of stringr has the same syntax: the first argument is a character vector, the second argument is a regex pattern. Use the package stringr to match, replace, or split strings according to certain patterns. Use backlash to escape quotes in a character: print("Package \"dplyr\"")Īutomatically escape double quotes within a string by enclosing it within single quotes (similarly to Stata compound quotes): # Stata: display(`"Package "dplyr""')Ĭombine strings with paste filename "x1+x2+x3" The package statar also includes functions that correspond to the Stata commands count, mode, xtile and _pctile