- May 18, 2021
- By Ismael Christian
Master Techniques for Efficient Use of Stata
Stata is a useful statistical software package that keeps data in memory..
read morePython and STATA are popular programming languages. The biggest difference between the two is that Python allows you to do a wide range of things while Stata is known for data analysis. The great advantage to any programmer is knowing how to use python within Stata for optimum results. In Stata 16 you can execute Python code within Stata. Stata has a new python command that gives you several subcommands helping you to call Python from Stata. It also enables you to output Python results within Stata.
If you want to read.dta (stata) file
Stata) - use file. dtaPython pd. read stata (“file.dta”
Stata) – Use var1 var2 using file.dta
Python- pd. read stata (“file.dta”), columns= [‘var1’, ‘var2’]
Stata)-Import Excel file using excel_file.xlsx
Python- pd. read excel (‘excel_file.xlsx’) Stata) import using csvfile.csv
Python) pd. read csv (“csvfile.csv”)
Stata) save file.dta, replacePython) df.to stata (“file.dta”)
In the above sentence, the parameter “replace” in the STATA command means that you will replace the pre-existing file.dta file with the present version you are saving.
Stata) - describePython) df.info ( )
Stata) countPython) len (df) or df. shape [0]
If you combine the count command with the If statement in Stata, you will get the number of observations that satisfy a given condition.
Example: count if name last== “Wood” (It will count the number of observations whose last name is Wood).
Stata) sort var1 var2Python) df, sort values ( [‘var1’, ‘var2])
Stata) Keep if< condition> drop if < condition>
You can start your Python journey within Stata if you know the common commands. Hope this cheat sheet comes in handy for you.
Stata is a useful statistical software package that keeps data in memory..
read moreMinitab software is essential as it assists companies and institutions to solve problems..
read moreMINITAB has released a new version of its software that has exciting features that..
read more