当前位置:首页 > 网站源码 > 正文内容

vbs编程代码大全(vbs代码编写软件)

网站源码5个月前 (06-12)160

20个常用的计量经济学R & Stata命令对比汇总

1、 导入csv数据文档

Stata:insheet using "auto.csv"

R:mydata <- read.csv("auto.csv")

2、改变定义路径

Stata:cd "mydirectory"

R:setwd("mydirectory")

3、打印 "hello world"

Stata:di "Hello World"

R:print("Hello World")

4、列出前五行变量数据

Stata:list in 1/5

R:head(mydata) 或者 mydata[1:5,]

5、导入/使用数据

Stata:use "mydata.dta", clear

R:load("mydata.Rdata")

6、保存并且替换数据

Stata:save "mydata.dta", replace

R:save.image("mydata.Rdata")

7、根据变量X进行排序

Stata:sort x y

R:mydata[order(mydata$x, mydata$y),]

8、相关分析

Stata:cor x y

R:cor(x,y)

9、帮助命令

展开全文

Stata:help command

R:help(command)

10、打开数据

Stata:edit

R:edit(mydata)

11、列联表

Stata:table x y

R:table(mydata$x,mydata$y)

12、描述分析

Stata:summarize

R:summary(mydata)

13、logit回归

Stata:logit y x

R:summary(glm(y~x,data=mydata,family="binomial"))

14、Probit回归

Stata:probit y x

R:summary(glm(y~x,data=mydata,family=binomial(link = "probit")))

15、回归分析

Stata:reg y x1 x2

R:summary(lm(y~x1+x2, data=mydata))

16、回归分析不带常数项

Stata:reg y x1 x2, nocon

R:summary(lm(y~x1+x2-1, data=mydata))

17、回归分析带if选项

Stata:reg y x if (x>0)

18、直方图

Stata:hist x

R:Stata:hist(mydata$x)

19、散点图

Stata:scatter x y

R:plot x y

20、列出所有数据

Stata:list

R:mydata

第一部分:普林斯顿大学:R-Stata数据探索入门

来源:http://www.princeton.edu/~otorres/

第二部分:Stata++R命令对比表

来源:https://github.com/EconometricsBySimulation/RStata/

下表提供了Stata命令到R的一些快速转换,因为R支持多个数据集,所以在使用数据访问/修改命令时,我们需要指定要操作的特定数据集。我们使用mydata作为目标的默认数据集。

Stata

R

Deion

cls

cat("\014") -OR- cat(rep("\n",50)) -OR- ctrl+L

Clears Stata output / R console

clear all

rm(list=ls)

Clears data, value labels, etc from memory

insheet using "foo.csv", comma names

mydata <- read.csv("foo.csv", header=TRUE)

Read csv file

cd "mydirectory"

setwd("mydirectory")

Change working directories

pwd

getwd

Display the working directory

reg y x1 x2

summary(lm(y~x1+x2, data=mydata))

Ordinary least squares with constant

reg y x1 x2, nocon

summary(lm(y~x1+x2-1, data=mydata))

Ordinary least squares without constant

if (x==y) {...}

if (x==y) {...}

Initial line condition use to evaluate whether a command(s) should be exectuted

reg y x if (x>0)

lm(y~x, data=subset(mydata,x>0))

Select a conditional subset of data

forvalues i=1/100 {...}

for (i in 1:100) {...}

Loop through integer values of i from 1 to 100

foreach i in "a" "b" "c" {...}

for (i in c("a","b","c")) {...}

Loop through a list of items

di "Hello World"

print("Hello World")

Prints "hello world" on screen

do "mydofile.do"

source("myR.R")

Call and run code file

use "mydata.dta", clear

load("mydata.Rdata")

Load saved workspace/data

save "mydata.dta", replace

save.image("mydata.Rdata")

Save current workspace/data

di 2345^2

2345^2

Calculate 2345 squared

logit y x

summary(glm(y~x,data=mydata,family="binomial"))

Perform logit maximum likelihood estimation

probit y x

vbs编程代码大全(vbs代码编写软件)

summary(glm(y~x,data=mydata,family=binomial(link = "probit")))

Perform probit maximum likelihood estimation

sort x y

mydata[order(mydata y),]

Sort the data frame by variable x

cor x y

cor(x,y)

Produce a table of correlates between x and y

help command

1. ?command 2. help(command)

Load the help file on a command

edit

edit(mydata)

Open data editor window (not recommended)

browse

View(mydata)

Visually inspect the dataset

summarize

summary(mydata)

Provide summary values for data

table x y

table(mydata y) # 1. ftable(y~x,data=mydata) # 2.

Two way table

hist x

hist(mydata$x)

Histogram of variable x

scatter x y

plot x y

Scatter plot of x on y

list

mydata

Print to screen all of the values of the data frame

list in 1/5

1. head(mydata) 2. mydata[1:5,]

Print to screen first 5 rows of data

generate x2=x^2

mydata x^2

Create a new variable x2 which is the square of x

replace x=y1+y2

1. mydata y1 + mydata x <- with(mydata, y1 + y2)

Change the x value of data to be equal to y1+y2

for i=1/10 { di `i' }

for (i in 1:10) print(i)

Print count from 1 to 10

replace x=0 if x<0

mydata x<0] <- 0

Replace all values of x less than 0 with zero

drop if x>100

mydata <- subset(mydata,!x>100)

Drop observations with x greater than 100

keep if x<100

mydata <- subset(mydata,x<100)

Keep observations with x less than 100

drop x

mydata$x <- NULL

Drop variable x from the data

keep x

mydata <- mydata$x

Keep only x in the data

append using "mydata2.dta"

mydata <- rbind(mydata, mydata2)

Append mydata2 to mydata

merge 1:1 index using "mydata2.dta"

merge(mydata,mydata2,index)

Merge two data sets together by index variable(s)

set obs 1000 gen x=rnormal

mydata$x <- rnorm(1000)

Generate 1000 random normal draws

set obs 1000 gen x=runiform

mydata$x <- runif(1000)

Generate 1000 random uniform draws

set obs 1000 gen x=rbinomial(10,.1)

mydata$x <- rbinom(1000, 10, .1)

Generate 1000 random binomial (10,.1) draws

count

nrow(mydata)

Count the number of observations in the data

foreach v of varlist * { rename v' v'old }

names(mydata) <- paste0(names(mydata),"old")

Rename all of the variables in the data ...old

rename oldvar newvar

colnames(dataframe)[colnames(dataframe)=="oldvar"] <- "newvar"

Rename variable.

clear set obs 100 gen x=rnormal(100) gen y=x*2 + rnormal(100)*5

mydata<-data.frame(x=x<-rnorm(100), y=x*2 + rnorm(100)*5)

Simulate a new data set with y dependent upon x

egen id = group(x y)

1. within(mydata, {ID <- ave(ID, list(x, y), FUN=seq_along)}) 2. mydata ID <- ave(ID, list(mydata y), FUN=seq_along)

Create an identifier ID from variables x and y

egen smallest = min(x y)

mydata %>% rowwise %>% mutate(smallest = min(c(x, y)))

For each row, find the smallest value within a set of columns

egen newvar = fcn(x y)

mydata %>% rowwise %>% mutate(newvar = fcn(c(x, y)))

For each row, apply a function to variables

扫描二维码推送至手机访问。

版权声明:本文由我的模板布,如需转载请注明出处。


本文链接:http://sdjcht.com/post/66880.html

分享给朋友:

“vbs编程代码大全(vbs代码编写软件)” 的相关文章

微信制作邀请函的小程序有哪些(微信什么小程序可以制作邀请函)

微信制作邀请函的小程序有哪些(微信什么小程序可以制作邀请函)

今天给各位分享微信制作邀请函的小程序有哪些的知识,其中也会对微信什么小程序可以制作邀请函进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、怎么制作微信邀请函...

苹果浏览器怎么看播放记录(苹果浏览器怎么看播放记录时间)

苹果浏览器怎么看播放记录(苹果浏览器怎么看播放记录时间)

本篇文章给大家谈谈苹果浏览器怎么看播放记录,以及苹果浏览器怎么看播放记录时间对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。 本文目录一览: 1、苹果手机百度贴吧直播的纪录如何看? 2、苹果...

小米手机怎么看已保存的网络密码(小米手机查看网络密码)

小米手机怎么看已保存的网络密码(小米手机查看网络密码)

今天给各位分享小米手机怎么看已保存的网络密码的知识,其中也会对小米手机查看网络密码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、小米手机怎样查看无线网络wi...

火影忍者手游买号去哪(火影忍者手游在哪买号)

火影忍者手游买号去哪(火影忍者手游在哪买号)

今天给各位分享火影忍者手游买号去哪的知识,其中也会对火影忍者手游在哪买号进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、问下火影忍者手游买号,在哪个平台买行?...

2022国少女排集训(2021年中国女排集训)

2022国少女排集训(2021年中国女排集训)

今天给各位分享2022国少女排集训的知识,其中也会对2021年中国女排集训进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、女排集训方式有新变化,设立训练营选拔...

soul数字藏品多少钱(soul币价格)

soul数字藏品多少钱(soul币价格)

今天给各位分享soul数字藏品多少钱的知识,其中也会对soul币价格进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、问问大家数字藏品 NFT的直购单价一般是多...