STATA basic code
- User
STATA basic code
- Assistant
Here is an introduction to some basic STATA commands that you may find helpful for data analysis tasks:
-
Importing and Exporting Data
-
STATA basic code
Here is an introduction to some basic STATA commands that you may find helpful for data analysis tasks:
Importing and Exporting Data
To import data from a CSV file:
import delimited "your_data.csv"
To export data to a CSV file:
export delimited using "your_output.csv", replace
Viewing and Describing Data
To open and browse a dataset:
use "your_dataset.dta"
browse
To describe the variables in the dataset:
describe
To summarize the statistics of variables:
summarize
To list the first 10 observations:
list in 1/10
Data Manipulation
To generate a new variable:
generate new_var = expression
To rename a variable:
rename old_var new_var
To replace values of a variable:
replace var = new_value if condition
To drop variables or observations:
drop var
drop if condition
Basic Data Analysis
To perform a linear regression:
regress dependent_var independent_var1 independent_var2
To perform a logistic regression:
logistic dependent_var independent_var1 independent_var2
To create a frequency table:
tabulate categorical_var
To create a cross-tabulation:
tabulate var1 var2
Graphs and Visualization
To create a histogram:
histogram numeric_var, frequency
To create a scatter plot:
scatter dependent_var independent_var
To create a box plot:
graph box numeric_var, over(group_var)
Saving Your Work
save "new_dataset.dta", replace
Running a Do-file (Batch Processing)
do "your_commands.do"
These are just a few basic commands to get started with STATA. As you become more familiar with the software, you will find a wide range of sophisticated commands at your disposal for more complex data analysis and statistical modeling.
Not yet included in a published release.