Presentation is loading. Please wait.

Presentation is loading. Please wait.

Econometrics 704 Emilio Cuilty

Similar presentations


Presentation on theme: "Econometrics 704 Emilio Cuilty"— Presentation transcript:

1 Econometrics 704 Emilio Cuilty
1. Introduction to Stata Econometrics 704 Emilio Cuilty

2 Stata Stata versions: On the available Memory (IC, SE, MP)
Sata works directly with the memory of the CPU Uses both commands and Windows New shortcuts available online Differentiates between upper and lower cases

3 Ventanas de Stata 3 2 4 1

4 Data File extension is .dta Thousands (,) and decimals (.)
Commands for memory management: Show memory: query memory Change memory: set memory #[b|k|m|g] [, permanently] Change max variables: set maxvar # [, permanently] Open an existent data in the directory: auto.dta Window: File/Open Comand: use filename [, clear nolabel] (use F:/auto.dta)

5 Data Erase data set: clear Description of the data:
window: Data/Describe data/Describe data in memory Command: describe Creating/editing: Editor Types: string, numeric, labeled numeric Missing values:: numeric (.) Labels: Variable: label variable varname ["label"] Values: Define: label define lblname # "label" [# "label" ...] Asiggment: label values varlist [lblname|.]

6 Command Sintax Help: help, search (web) Basic sintax:
[prefix: ] command [varlist] [=exp] [if exp] [in range] [weight] [, options] […]: Options and qualifiers prefix: repeats execution of a command or modifies either the input or output of the command varlist: variable list command: Stata command exp: algebraic expression range: observation range weight: How to weight obs options: options for that command

7 Expresions Operators Functions help functions Errors

8 Examples: Commands Descriptive Stats::
summarize [varlist] [if] [in] [weight] [, options] Examples: sum by foreign: sum length sum length if price>= sum length price in 1/10 Frequency table: tabulate varname [if] [in] [weight] [, options] Show values of expressions and scalars: display [“”] [exp]

9 Variables, observations
Create generate: generate [type] newvar[:lblname] =exp [if] [in] egen: egen [type] newvar = fcn(arguments) [if] [in] Remplace replace: replace oldvar =exp [if] [in] delete/lkeep (drop/keep) Variables: {drop|keep} varlist Observations: {drop|keep} if exp Observations Rnge.: {drop|keep} in range [if exp]

10 do and log files do File with a list of commands to execute
Is a text file with extension .do To introduce comments in the file: *texto, //texto// To run a do file: {do|run} filename [, nostop ] Log File that keeps track on the results window Extension .log Start a log: log using filename [, append replace [text|smcl] ] Close a log: log close See the log: view filename.smcl

11 Scalars Save a unique number or text
A Common use if for saving estimates Create: scalar scalar_name = exp List content: scalar { dir | list } [ _all | scalar_names ] delete: scalar drop { _all | scalar_names }

12 Matrix Stata saves number or text matrixes Two ways:
command ( usually using the prefix matrix) Mata program Start program: mata Back to stata: end

13 Matrix: commands Operators Functions help matrix functions

14 Matrices: Mediante comandos
Create matrix matrix_name = {matrix_expression, (#,..,# \ #,..,# \ #,..,#)} (, ): column (\): row See: matrix list matrix_name Directory: matrix dir Rename: matrix rename oldname newname delete: matrix drop {_all | matrix_name} Choose submatrix: matrix A = B[ri..rj, ck..cs] replace: matrix A[ri..rj, ck..cs] = B Matrix to Variable: svmat A Variable to Matrix: mkmat varlist [if] [in] [, matrix(matname) …]

15 Using results from Stata commands
r clase e clase From data, but not from estimation Are saved in r() Dissapear after another command is used Example: use auto sum mpg return list scalar rango = r(max) – r(min) display “mpg range = ” rango From estimation Saved in e() Example: regress mpg price weight ereturn list matrix b = e(b) matrix list b

16 Macros global local global variables “trunk weight length”
Characters list Reduces the burden of coding Two types: local: only available in do file or in one session global: once defined available across do files or sessions Ejs: global local global variables “trunk weight length” sum $variables local variables “trunk weight length” sum `variables'

17 Looping commands Ways of repeating the same command several times
foreach: Repeats over a list of items forvalues: Repeats over consecutive numbers while: Repeats command until a condition is met


Download ppt "Econometrics 704 Emilio Cuilty"

Similar presentations


Ads by Google