Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

27 commonly used stata commands (2)

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

27 commonly used Stata commands

[1] directly import data in csv format

Insheet using name.csv, clear

[2] modify variable length

Format var 20.2g

[3] Delete duplicate values

Sort var1 var2

Duplicatesdrop var1 var2, force

[4] data merge

Use data1, clear

Merge m:m var1var2 using data2

Drop if _ merge==2

Drop if _ merge==1

Drop _ merge

[5] generate the lag term of the first period

Tsset stkcd accper

Gen newvarname=L.varname

[6] convert text to numeric variables

GenBigN=0

ReplaceBigN=1 if strmatch (dadtunit, PricewaterhouseCoopers *)

[7] Delete records with missing values

Egen mis=rowmiss (_ all)

Drop if mis

Drop mis

[8] Industry division

Clonevarsic2=ind

Order stkcd accper sic2

Replace sic2=substr (sic2,1,1) if substr (sic2,1,1)! = "C"

Replace sic2=substr (sic2,1,2) if substr (sic2,1,1) = = "C"

Tabulate sic2 accper

[9] date is reserved only for year

Drop if substr (reptdt, 6. 2)! = "12"

Replace reptdt=substr (reptdt,1,4)

Gen accper=real (reptdt)

[10] data disaggregation

Split date, parse (-) destring ignor ("-")

[11] calculate the number of days between two dates

G td=date (trading_date, "YMD")

G ed=date (eventdate, "YMD")

Form td ed td

G d=ed-td

[12] generate industry and year dumb variables

Tab year, gen (year)

Tab industry, gen (industry)

[13] Winsorize processing of the data

Findit winsor2

Winsor2 varname, replace cut (1 99)

[14] descriptive statistics

Tabstat var1var2, stat (n min mean median p25 p75 max sd), if groupvar==0 or 1

Logout, save (name) word replace: tabstat var, stat (n min mean p50 max sd) col (stat) f (% 9.2g)

[15] contingency table of two variables

Tabulate var1 var2, row chi2 taub gamma

[16] mean T test between two samples

Ttest var, by (groupvar)

[17] median Z test of two samples

Ranksum var, by (groupvar)

[18] Pearson/Spearman coefficient

Spearmanx

N mata

X=st_data (., "x")

C=correlation (x)

N=rows (c)

B=strofreal (lowertriangle (c) + uppertriangle (st_matrix ("r (Rho)")), "9.3f")

P=st_matrix ("r (P)")

For (iTunes 2; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report