代写ECON4003 INTRODUCTION TO STATA代写Processing

ECON4003

INTRODUCTION TO STATA

WEEK 3

1  Introduction

1.1    Materials and setup

●    Find class materials on Moodle page

●    Download the folder for Stata session and unzip it!

1.2  Organisation

●    Make comments in your Do-file rather than on self-printed hand-outs

●     save on flash drive or email to yourself

1.3    Lab description

●    This is an introduction to Stata

●    Assumes no/very little knowledge of Stata

●    Learning objectives:

o  Familiarise yourself with the Stata interface

o  Get data in and out of Stata

o  Compute statistics and construct graphical displays

o  Compute new variables and transformations

1.4    What is Stata? Statistics and Data Analysis

●   A statistical package that includes a wide variety of capabilities

o Data management

o Statistical and econometric analysis

o Graphics etc.

●   Widely used in the fields of economics, finance, political science, sociology, biomedicine and epidemiology

●   Three main versions

o Stata/IC (Intercooled): mid-sized datasets

o Stata/SE (Special Edition ): large datasets

o Stata/MP (Multi-processor ): fastest version (for quad-core, dual-core, and multicore/multiprocessor computers)

1.5    Where you can download Stata?

●   See Stata Installation Guide under Course Resources > Resources for Stata

●   Contact IT Helpdesk for any technical issues

1.6    Stata interface

 

●     Command window:

o Type the instructions we want Stata to execute

o Alternatively, type in the Do-file (see next section)

●     Results window

o Display the results and output after a command is executed

●     Review window

o Keeps arecord of all the commands used/the input history

●    Variables window

o Shows all the variables in the dataset

●     Properties window

o Indicates the properties of a highlighted variable or save any files

●    Current working directory

o Shows the current directory in the file system of your computer from where Stata will read or save any files

1.7    Do-files

●    You can type all the same commands into the Do-file that you would type into the command window

●     BUT...the Do-file allows you to save your commands

●    Saving commands in Do-file allows you to keep a written record of everything you have done to your data

o  Allows easy replication

o  Allows you to go back andre-run commands, analyses and make modifications

1.8    Stata menu

●    An alternative way to tell Stata what you would like it to do is to use menus and dialogs.

●     Stata’s Data, Graphics, and Statistics menus provide point-and-click access to almost every command in Stata.

1.9    Stata help

●    To get help in Stata type “help” followed by topic or command, e.g., help codebook

1.10  General Stata command syntax

●    Most Stata commands follow the same basic syntax:

command varlist, option

1.11  Hand calculator

●     Stata can be used as a calculator using the command: display

display 4+5

dis  3^5

dis  10/5

1.12  Commenting

●    Any command in Stata that is preceded by a star character (*) will be regarded as comment, and therefore, not executed

*This is a comment

2  Getting data into Stata

2.1  Data file commands

●    First, we set the working directory to the folder you saved your data by selecting:

File > Change working directory 

●    Next, we want to open our data file

●    Open/save data sets with "use" and "save"

use “nlsw88small.dta”, clear

save “nlsw88lab1.dta”, replace

The US National Longitudinal Study of Young Women 1998 extract, nlsw88small.dta, contains data of

500 women in their 30s and early 40s to study their labourforce patterns.

2.2 Variable list

Variable                                                            Description

idcode

NLS id

age

age at current year

race

race

married

=1 if married; 0 otherwise

never_married

=1 if never married; 0 otherwise

grade

current grade completed, numerical

collgrad

=1 if college graduate; 0 otherwise

south

=1 if lives in south; 0 otherwise

smsa

=1 if lives in SMSA; 0 otherwise

c_city

=1 if lives in central city; 0 otherwise

industry

industry category

occuptation

occupational category

union

=1 if union worker; 0 otherwise

wage

hourly wage

hours

usual hours worked

ttl_exp

total work experience (years)

tenure

job tenure (years)

3  Statistics and graphs

3.1  Operators

3.1.1 Relational operators

●    >          // greater than

●    <          // less than

●    >=       // greater than or equal

●    <=       // less than or equal

●    ==       // equal

●    !=        // not equal

3.1.2 Logical operators

●    &         // and

●     |          // or

●     !           // not

3.2  Frequently used commands for reviewing and inspecting data

●     describe          // labels, storage type etc.

describe

des wage age

Exercise: produce a summary describing the variables “union” and “tenure”

●     codebook       // storage type, unique values, labels

codebook wage

Exercise: produce a codebook for the variables “tenure” and “hours”

●    sum                 // statistical summary (mean, sd, min/max etc.)

sum wage

sum wage, detail

sum wage if married==1

sum wage if age>=40 & age<=44

Exercise 1: compute the summary statistics for the variable “tenure”

Exercise 2: compute summary statistics for the variable “hours” for individuals aged 40 or 44

●    tab                   // (cross) tabulate frequency counts

tab industry

tab industry, nolabel

tab industry race

Exercise 1: produces a table of frequency counts for the variable “occupation”

Exercise 2: produce a two-way table of frequency counts for the variable “occupation” and “collgrad”

●    browse            // view the data in a spreadsheet-like window

browse

browse wage age

3.3 Basic graphing commands

●    graph pie / bar / hbar          // present categorical data

●     save graphs as jpeg format

graph pie, over(industry)

graph bar, over(race)

graph hbar, over(occupation)

Exercise 1: draw pie chart for “occupation”

Exercise 2: create a bar graph for the variable “married”

Exercise 3: create a horizonal bar graph for the variable “industry”

●    hist                  // univariate distribution(s)

hist wage

hist wage, percent

hist wage, freq

hist wage, normal

Repeat the exercise above for the variable “hours”

●    twoway scatter          // view bivariate distributions with scatterplots

twoway scatter wage tenure

twoway scatter wage tenure, by(race)

Exercise 1: create a scatter plot of “wage” on “ttl_exp”

Exercise 2: create a scatter plots of “wage” on “ttl_exp” by “married”

4  Basic data management

4.1  Generating and replacing variables

●    gen                  // create new variables

gen age2 = age^2

gen lnwage = ln(wage)

Exercise: create a new variable “totwage” which is “wage” multiplied by “hours”

●    replace            // replace variables with new values

replace age2 = age2/100

Exercise: replace “totwage” with the natural log of “totwage”

4.2  Renaming and deleting variables

●    rename            // change variable names

rename age2 agesq

Exercise: rename the variable “totwage” as “lntotwage”

●    drop                // delete variables

drop agesq lnwage

Exercise: drop “totwage”

Save the data and your do-file before you quit the session.

 


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图