User:Bequw/Stata to R
Todo: Look for the chapter and section references. Similar sites: http://hyperpolyglot.org/numerical-analysis http://rosettacode.org/wiki/Category:R
Getting Started
edit- help
- search
Data manipulation and management
editBasic data commands
edit- codebook
- data management
- data types
- datetime
- describe
#TODO mention str() - edit
- format
- inspect
- label
- list
- missing values
- rename
>names(df)[match("oldname",names(df))] = "newname" #note this won't give an error if there is no variable named "oldname" - save
- sort #This is not required in R before merging, aggregating, repeated group analysis
>df = df[order(df$PrimarySortCol, df$SecondarySortCol),] - use
- varmanage
Creating and dropping variables
edit- clear
see remove() #TODO note how to clear _all - compress
- drop
>df = df[, !names(df) %in% c("var1todrop", "var2todrop")] - egen/generate
If the dataset already has observations can do stuff like
>df$sum = df$x1 + df$x2
>df$id = NA
If you have an empty dataframe (greated by something like data.frame()) then you can do stuff like
>df$sum = numeric() - functions
Functions and expressions
edit- egen
- functions
Dates and times
edit- bcal
- datetime
- datetime business calendars
- datetime business calendars creation
- datetime display formats
- datetime translation
Loading, saving, importing, and exporting data
edit- edit
- export
- haver
- import
- import excel
- import sasxport
- infile (fixed format)
- infile (free format)
- infix (fixed format)
- input
- insheet
- odbc
- outfile
- outsheet
- save
- sysuse
- use
- webuse
- xmlsave
Combining data
edit- append
- mi append
- cross
- joinby
- merge
- mi merge
Reshaping datasets
edit- collapse
- >aggregate
- contract
- expand
- expandcl
- fillin
- obs
- reshape
- mi reshape
- rolling
- separate
- ssd
- stack
- statsby
- xpose
Labeling, display formats, and notes
edit- format
- label
- label language
- labelbook
- notes
- varmanage
Changing and renaming variables
edit- clonevar
- destring
- encode
- generate
- mvencode
- order
- recode
- rename
- rename group
- split
- varmanage
Examining data
edit- cf
- codebook
- compare
- count
- describe
- ds
- duplicates
- edit
- gsort
- inspect
- isid
- lookfor
- misstable
- mi describe
- mi misstable
- pctile
- stdescribe
- summarize
- svy: tabulate oneway
- svy: tabulate twoway
- tabdisp
- table
- tabstat
- tabulate oneway; tabulate twoway
- >table()
- tabulate, summarize()
- xtdescribe
File manipulation
edit- cd
>getwd()
>setwd("Path") #Window's default windows folder separator character '/' will have be replaced with '\' or fully escaped '//' to work right. If you working interactively, you can enter >scan('', '', n=1) and then at the prompt past directly a windows folder path (with '/'s in it) and it will auto-escape it for you. - cf
- changeeol
- checksum
- copy
- dir
- erase
- filefilter
- mkdir
- rmdir
- type
- zipfile
Miscellaneous data commands
edit- corr2data
- drawnorm
- dydx
- icd9
- ipolate
- range
- sample
Multiple imputation
edit- mi add
- mi append
- mi convert
- mi copy
- mi describe
- mi erase
- mi expand
- mi export
- mi export ice
- mi export nhanes1
- mi extract
- mi import
- mi import flong
- mi import flongsep
- mi import ice
- mi import nhanes1
- mi import wide
- mi merge
- mi misstable
- mi passive
- mi ptrace
- mi rename
- mi replace0
- mi reset
- mi reshape
- mi set
- mi stsplit
- mi update
- mi varying
- mi xeq
- mi XXXset
- noupdate option
- styles
- workflow