![shift enter in excel stata shift enter in excel stata](https://www.stata.com/stata-news/news30-2/format-excel/i/putexcel2b.gif)
put the mean of age in a cell using the string() function Note that I must use double quotes in the command putexcel B1 = “`meansd'” because meansd is a string. Second, I create a local macro named meansd that combines meanage and sdage into a single expression. The string() function allows me to specify one decimal place. First, I store r(mean) and r(sd) to the local macros meanage and sdage, respectively.
![shift enter in excel stata shift enter in excel stata](https://cdn.wallstreetmojo.com/wp-content/uploads/2019/02/uppercase-in-excel.jpg)
I could also report the mean and standard deviation in a single cell. You can view a complete list of codes for numeric formats in the Appendix of putexcel.Įxample 4: Formatting numbers with the string() function putexcel B1 = `r(mean)', nformat(number_d2) putexcel set putexcel2.xlsx, sheet(example3) modify For example, I could display the mean with two decimal places using the option number_d2. Stata includes many shortcut format codes that can be used with nformat(). You can view a complete description of Excel’s formatting options in the Options section of putexcel advanced.Įxample 3: Formatting numbers with Stata formats putexcel set putexcel2.xlsx, sheet(example2) modify For example, I could display the mean with three decimal places using the option nformat(“#.#”). I can specify the display format of a number using Excel formats in the nformat() option. I can open the resulting Excel file and see that the mean was successfully written to cell B2.Įxample 2: Formatting numbers with Excel formats Note: file will be replaced when the first putexcel command is issued putexcel set putexcel2.xlsx, sheet(example1) replace This tells Stata that I want to write the value of r(mean) to cell B2. Note that r(mean) is enclosed in single quotes. I can then write the expression “Mean Age = ” to cell A1 and the expression `r(mean)’ to cell B1. I begin by setting the destination to the sheet “example1” in the file putexcel2.xlxs. The mean is stored in the scalar r(mean). I can type return list after summarize age to see a list of returned results. For example, I might wish to write the mean of age to Excel. We can write each of these to an Excel table using putexcel. Many Stata commands return scalars, macros, and matrices. I am using a subset of the data and have relabeled some of the variables so don’t be concerned if your numbers don’t match mine exactly.Įxample 1: Writing returned results to Excel
SHIFT ENTER IN EXCEL STATA DOWNLOAD
You can download the dataset used in the examples by typing webuse nhanes2. You may wish to use a similar approach when creating large reports. I could create a separate Excel file for each example, but I would prefer to have a single file with multiple sheets. Putexcel set putexcel2.xlsx, sheet(example8) modify Putexcel set putexcel2.xlsx, sheet(example2) modify Putexcel set putexcel2.xlsx, sheet(example1) replace So the putexcel set commands will look like this: These are important steps toward our goal of automating the creation of reports in Excel.īefore we begin the examples, I want to point out that I am going to create a single Excel file called putexcel2.xlsx and write each example to a separate sheet within that file.
SHIFT ENTER IN EXCEL STATA HOW TO
I will even show you how to write formulas to Excel to create calculated cells. Today, I want to show you how to write more complex expressions such as macros, graphs, and matrices. In my last post, I showed how to use putexcel to write simple expressions to Microsoft Excel and format the resulting text and cells.