Stata Help

Inputting Data with the input Command

To enter lines of data into Stata without having to rely heavily on the enter key, you can use the input command. Assuming you have created your variables already, typing input will cause Stata to list your variables and a green number indicating your current observation. Stata picks up where you left off, so in this case it prompts me for the seventh line of data.


You can now enter lines of data into the command line. Type a line of data (values separated by spaces), then hit enter. That data shows up unformatted and the next line number appears. You can continue to type data in this fashion until you are satisfied. When you are done, simply type end and Stata will terminate the input command.

The input command can also be used if you do not yet have any variables created. In this case simply type input [varname1] [varname2] [varnamen] and Stata will create the variables for you (and prompt you for the first and subsequent observations).

If no variable type is specified, Stata assumes that the new variable is numeric and will not accept string input. To create a string variable, you have to specify str and the length before the variable. For instance: to create and begin inputting the origin state, the population, and the percent of persons self-identified as alcohol-dependent, the command would look as follows: input str2 state pop percent

The above would tell Stata that the state variable is a string variable of 2 characters (wa, or, pa, etc.). 

To input string content, you need to put double quote marks (") around the string so that Stata knows when it starts and stops. For instance, the first row of input for the command above might look like "wa" 300 22

Back to Tutorials

Back to Data Entry