• Laura Whiting

The Input Command

The input command allows the creation of small datasets within Stata. When you are performing analyses or running a do file on a large dataset, it can be helpful to first run a test case. By creating a small dataset using the input command, you can run your do file or analysis on a small dataset to confirm you are getting the results you expect.

How to Use:

The first line is the name of the variables, the second and third and fourth etc. lines are each a single observation, and the last line contains only end, which tells Stata you are finished inputting data.

If the variable is a string you will need to tell Stata this by adding str(#) before the variable name, so input var1 var2 becomes input var1 str(10) var2. The # is the byte length of the string. Most alphanumeric and other characters are stored as a single byte, however some characters will take up more than one so be careful when inputting strings with this command.

Worked Example:

I want to create a list of fruits and their prices. In the command pane I type the following:

To see the results I list the dataset with:

Which gives the following output:

Once you have created your small dataset you can then run analysis or do files on it. This allows you to troubleshoot and find any issues with the do file or analysis before running it on a larger dataset. It can also be used to create small test cases, to make sure your analysis or do file is giving the answer it is supposed to.

19 views0 comments

© 2020 by Survey Design and Analysis Services. 

  • LinkedIn
  • Facebook
  • Twitter
  • YouTube