1 / 113

Session I How to use STATA & Basic Data Management Commands

Session I How to use STATA & Basic Data Management Commands. What will be covered?. Introduction to STATA Software General Guidelines in Data entry Data Management in STATA. Introduction to STATA. Open & Close the Output File. To open the log file log using “directorypathfilename.log”

Télécharger la présentation

Session I How to use STATA & Basic Data Management Commands

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Session IHow to use STATA& Basic Data Management Commands

  2. What will be covered? • Introduction to STATA Software • General Guidelines in Data entry • Data Management in STATA

  3. Introduction to STATA

  4. Open & Close the Output File To open the log file log using “directory\path\filename.log” log using d:\trials\zinc.log To close log close zinc.dta

  5. To Open Log (Output) File

  6. To Close the Log File

  7. Append & Replace the Existing Log File To append the existing log file log using d:\trials\zinc.log, append To replace the existing log file log using d:\trials\zinc.log, replace

  8. Open the Data File To open the data file use “directory\path\filename.dta” use d:\trials\zinc.dta To save save zinc.dta zinc.dta

  9. To Make A New Directory

  10. To Change the Directory

  11. General Guidelines in Data Entry Rows in the datasheet should contain individual information - Record. Each column should contain values of a single entity of all the individuals – Variable. Variable name should not exceed more than eight characters. Variables can be either numeric or string or alphanumeric. A numeric variable must posses only numbers. In any datasheet, identification number is must.

  12. DATA DESCRIPTION

  13. Data Management using STATA

  14. Data Management using STATA • Inputting Data • Editing Data • Creating and Changing Variables • Saving and Reusing Data • Data Reorganization • Merging and Appending datasets

  15. Inputting Data • Enter data from keyboard • input varlist • input str25 name age str1 sex • Best way is copy from excel and directly paste the data to STATA editor • Transfer from other programs

  16. Arithmetic Operators + (Addition) - (Subtraction) * (Multiplication) / (Division) ^ (Raise to power)

  17. Relational Operators > (greater than) < (less than) > = (greater than or equal) < = (less than or equal) = = (equal) != (not equal)

  18. Logical Operators & (and) | (or) != (not equal)

  19. Expressions If – used when expression is to be specified with the condition In – used when range is to be specified in the condition

  20. Editing Data • Edit using Data Editor • edit [varlist] [if] [in] • edit treatment centre age • edit treatment age if centre==3&age>25

  21. Browsing Data • List using Data Editor • browse [varlist] [if] [in] • browse treatment centre age • browse treatment age if centre==3&age>25

  22. Do this Exercise… zinc.dta • Edit the following: • pcode, treatment and cough only for centre 4 • browse for the same and feel the difference

  23. Creating & Changing Variables • Create new variable • generate newvar = exp [if] [in] • gen totstl24= s1_tstool_wt+ s2_tstool_wt+ s3_tstool_wt

  24. Do this Exercise…… zinc.dta Generate total stool output from 0-48 hours

  25. Creating & Changing Variables…contd • Change contents of existing variable • To replace • replace oldvar =exp [if] [in] • replace sodium1 = . if sodium1==0 • To recode • recode varlist (erule) [(erule) ...] [if] [in] • recode age min/6=1 7/11=2 12/max=3 , gen(agecat)

  26. Do this Exercise…… Ex 1: Replace all zeros in serum Potassium as missing. Ex 2: Recode pre admission diarrhea duration into 0-24h, 25-72h and > 72h zinc.dta

  27. Creating & Changing Variables…contd • Rename the existing variable • rename oldvarname newvarname • ren tlc_t2 tlc2 • ren tlc_t3 tlc3 • Eliminate the existing variable • To drop • drop varlist • drop name address • To keep • keep varlist • keep idno age sodium albumin-tlc zinc.dta

  28. Saving & Reusing Data in Stata Format • To Save data • save filename.dta • save zinc, replace • clear • To reuse data • use filename • use zinc zinc.dta

  29. Data Reorganization • Sorting observations and changing variable order • To sort • sort varlist [in] {ascending} • sort pcode • Move specified variables to front of dataset • order varlist • Move one variable to specified position • move varname1 varname2 • Alphabetize specified variables and move to front of dataset • aorder [varlist] zinc.dta

  30. Data Reorganization …contd • Convert data from wide to long • reshape long stubnames, i(varlist) j(varname) • reshape long albumin, i(pcode) j(time) Wide Shape Data Long Shape Data

  31. Data Reorganization …contd Convert data from long to wide reshape wide stubnames, i(varlist) j(varname) reshape wide albumin, i(pcode) j(time) Long Shape Data Wide Shape Data

  32. Do this Exercise… Convert serum zinc from wide to long shape data using zinclab.dta zinclab.dta

  33. Answer!!! zinclab.dta

  34. Merging & Appending Datasets • To append datasets • append using filename • use zinc1.dta • append using zinc2.dta • To merge datasets • merge [varlist] using filename • use zinclab • sort pcode • save zinclab, replace • use zincprognostic • sort pcode • merge pcode using zinclab zinclab.dta

  35. Do this Exercise… Merge file 1 (zinclab.dta)with file 2 (zincprognosis.dta) zinclab.dta

  36. Session IIData Cleaning & Preparing Data for Analysis

  37. Preparing Data for Analysis Inclusion criteria ≤ 35 months old children

  38. Preparing Data for Analysis …contd

  39. Do this Exercise… Inclusion criteria for the study was pre admission diarrhea duration < 7 days Ex 1: Convert pre admission diarrhea duration from hours to days using zincclean.dta Ex 2: Find values beyond expected range zinc.dta

  40. Answer!!!

  41. Preparing Data for Analysis …contd

  42. Preparing Data for Analysis …contd

  43. Preparing Data for Analysis …contd

  44. Do this Exercise… Do similar exercise for hemoglobin using zinc.dta zinc.dta

  45. Answer!!!

  46. Preparing Data for Analysis …contd What do you mean by 1 & 2??? zinc.dta

  47. Preparing Data for Analysis …contd Label name

  48. Preparing Data for Analysis …contd zinc.dta What is wrong and how to correct it???

More Related