├── CSMAR Cleaning.do
├── CSMAR CtrlVars Cleaning Log.smcl
├── ControlVarsDetail.dta
├── Image
├── Figure2.png
└── tmp.txt
├── LICENSE
└── README.md
/CSMAR Cleaning.do:
--------------------------------------------------------------------------------
1 | log using "CSMAR CtrlVars Cleaning Log", replace name(ShutterZorADXMU20241231)
2 | * =============================================================
3 | /* Author Information */
4 |
5 | * Name: Shutter Zor(左祥太)
6 | * Email: Shutter_Z@outlook.com
7 | * Affiliation: Accounting Department, Xiamen University
8 | * Date: 2024/12/31
9 | * Version: V3.0
10 |
11 | * =============================================================
12 |
13 |
14 |
15 | /* 常用控制变量数据清洗教程(ControlVarsDetail.dta)*/
16 | /* 说明:本次样本为所有上市公司2001-2023(含2001与2023)的数据 */
17 |
18 |
19 |
20 | ********************************************************************************
21 | // 开始时间记录:
22 | dis "`c(current_date)' `c(current_time)'"
23 |
24 | *- 清洗上市公司基本信息数据
25 | /* 包含变量:STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE */
26 |
27 | import excel using "DataA-Original/STK_LISTEDCOINFOANL.xlsx", first clear
28 | labone, nrow(1 2) concat("_")
29 | drop in 1/2
30 |
31 | *- 生成变量 - 观测年份
32 | gen YEAR = substr(EndDate,1,4)
33 | destring YEAR, replace
34 |
35 | *- 生成变量 - 成立年份至观测年份的 AGE1
36 | gen EstablishYear = substr(EstablishDate,1,4)
37 | destring EstablishYear, replace
38 | gen AGE1 = YEAR - EstablishYear
39 |
40 | *- 生成变量 - 上市年份至观测年份的 AGE2
41 | gen ListingYear = substr(LISTINGDATE,1,4)
42 | destring ListingYear, replace
43 | gen AGE2 = YEAR - ListingYear
44 | drop if AGE2 < 0 // 去掉部分不合理的观测样本
45 |
46 | *- 生成变量 - 股票市场板块 MARKET
47 | gen MARKET = "深证主板A股" if substr(Symbol,1,2) == "00"
48 | replace MARKET = "深证创业板" if substr(Symbol,1,2) == "30"
49 | replace MARKET = "深证B股" if substr(Symbol,1,2) == "20"
50 | replace MARKET = "上证主板A股" if substr(Symbol,1,2) == "60"
51 | replace MARKET = "上证科创板" if substr(Symbol,1,2) == "68"
52 | replace MARKET = "上证B股" if substr(Symbol,1,2) == "90"
53 | replace MARKET = "北证A股" if substr(Symbol,1,2) == "43" | substr(Symbol,1,2) == "83" | substr(Symbol,1,2) == "87"
54 |
55 | *- 重命名变量
56 | rename (Symbol ShortName IndustryName IndustryCode PROVINCECODE PROVINCE CITYCODE CITY LISTINGSTATE) (STKCD STKNM INDNM INDCD PROVCD PROVNM CITYCD CITYNM STATE)
57 |
58 | *- 保留有效变量
59 | keep STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE1 AGE2
60 |
61 | *- 补充变量标签
62 | label var YEAR "观测年份"
63 | label var MARKET "股票市场板块"
64 | label var AGE1 "从成立年份到观测年份的年龄"
65 | label var AGE2 "从上市年份到观测年份的年龄"
66 |
67 | *- 排序与保存数据
68 | order STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE1 AGE2
69 | label data "基本信息相关变量11+年龄 - From Shutter Zor"
70 | save "DataB-Hub/Data1.dta", replace
71 |
72 | /* 本部分生成的 Data1 用于后续合并 */
73 | /* STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE */
74 |
75 | // 结束时间记录:
76 | dis "`c(current_date)' `c(current_time)'"
77 | ********************************************************************************
78 |
79 |
80 |
81 | ********************************************************************************
82 | // 开始时间记录:
83 | dis "`c(current_date)' `c(current_time)'"
84 |
85 | *- 清洗财务报表相关数据
86 | /* 包含变量:CFO GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT */
87 |
88 | *- 资产负债表
89 | import excel using "DataA-Original/FS_Combas.xlsx", first clear
90 | labone, nrow(1 2) concat("_")
91 | drop in 1/2
92 |
93 | *- 仅保留合并报表数据
94 | keep if Typrep == "A" // A为合并报表,B为母公司报表
95 |
96 | *- 仅保留年报数据
97 | keep if substr(Accper,6,2) == "12" // 12月的年报
98 |
99 | *- 重命名变量
100 | rename (Stkcd ShortName A001121000 A001000000 A002000000 A003000000) (STKCD STKNM 其他应收款 总资产 总负债 所有者权益)
101 |
102 | *- 生成变量 - 观测年份
103 | gen YEAR = real(substr(Accper,1,4))
104 |
105 | *- 生成变量 - 资产负债率 LEV
106 | destring 总负债 总资产, replace // 转为数值变量,方便计算
107 | gen LEV = 总负债 / 总资产
108 |
109 | *- 生成变量 - 大股东资金占用 OCCUPY
110 | destring 其他应收款, replace
111 | gen OCCUPY = 其他应收款 / 总资产
112 |
113 | *- 生成变量 - 公司规模 SIZE
114 | gen SIZE = ln(总资产)
115 |
116 | *- 保留有效变量
117 | keep STKCD STKNM 总资产 所有者权益 YEAR LEV OCCUPY SIZE
118 |
119 | *- 补充变量标签
120 | label var YEAR "观测年份"
121 | label var LEV "资产负债率"
122 | label var OCCUPY "大股东资金占用"
123 | label var SIZE "公司规模"
124 |
125 | *- 保存数据
126 | label data "资产负债表数据 - From Shutter Zor"
127 | save "DataB-Hub/Data2.dta", replace
128 |
129 | *- 利润表
130 | import excel using "DataA-Original/FS_Comins.xlsx", first clear
131 | labone, nrow(1 2) concat("_")
132 | drop in 1/2
133 |
134 | *- 仅保留合并报表数据
135 | keep if Typrep == "A" // A为合并报表,B为母公司报表
136 |
137 | *- 仅保留年报数据
138 | keep if substr(Accper,6,2) == "12" // 12月的年报
139 |
140 | *- 重命名变量
141 | rename (Stkcd ShortName B001101000 B001210000 B002000000) (STKCD STKNM 营业收入 管理费用 净利润)
142 |
143 | *- 生成变量 - 观测年份
144 | gen YEAR = real(substr(Accper,1,4))
145 |
146 | *- 生成变量 - 营业收入增长率 GROWTH
147 | destring 营业收入, replace
148 | egen STKID = group(STKCD)
149 | xtset STKID YEAR
150 | bys STKID: gen GROWTH = (营业收入 - L.营业收入) / L.营业收入
151 |
152 | *- 生成变量 - 管理层费用率 MFEE
153 | destring 管理费用, replace
154 | gen MFEE = 管理费用 / 营业收入
155 |
156 | *- 保留有效变量
157 | keep STKCD STKNM YEAR 营业收入 净利润 GROWTH MFEE
158 |
159 | *- 补充变量标签
160 | label var YEAR "观测年份"
161 | label var GROWTH "营业收入增长率"
162 | label var MFEE "管理层费用率"
163 |
164 | *- 保存数据
165 | label data "利润表数据 - From Shutter Zor"
166 | save "DataB-Hub/Data3.dta", replace
167 |
168 | *- 现金流量表 - 直接法
169 | import excel using "DataA-Original/FS_Comscfd.xlsx", first clear
170 | labone, nrow(1 2) concat("_")
171 | drop in 1/2
172 |
173 | *- 仅保留合并报表数据
174 | keep if Typrep == "A" // A为合并报表,B为母公司报表
175 |
176 | *- 仅保留年报数据
177 | keep if substr(Accper,6,2) == "12" // 12月的年报
178 |
179 | *- 重命名变量
180 | rename (Stkcd ShortName C001000000) (STKCD STKNM 经营活动产生的现金流净额直接法)
181 |
182 | *- 生成变量 - 观测年份
183 | gen YEAR = real(substr(Accper,1,4))
184 |
185 | *- 保留有效变量
186 | keep STKCD STKNM YEAR 经营活动产生的现金流净额直接法
187 |
188 | *- 补充变量标签
189 | label var YEAR "观测年份"
190 |
191 | *- 保存数据
192 | label data "现金流量表数据直接法 - From Shutter Zor"
193 | save "DataB-Hub/Data4.dta", replace
194 |
195 | *- 现金流量表 - 间接法
196 | import excel using "DataA-Original/FS_Comscfi.xlsx", first clear
197 | labone, nrow(1 2) concat("_")
198 | drop in 1/2
199 |
200 | *- 仅保留合并报表数据
201 | keep if Typrep == "A" // A为合并报表,B为母公司报表
202 |
203 | *- 仅保留年报数据
204 | keep if substr(Accper,6,2) == "12" // 12月的年报
205 |
206 | *- 重命名变量
207 | rename (Stkcd ShortName D000100000) (STKCD STKNM 经营活动产生的现金流净额间接法)
208 |
209 | *- 生成变量 - 观测年份
210 | gen YEAR = real(substr(Accper,1,4))
211 |
212 | *- 保留有效变量
213 | keep STKCD STKNM YEAR 经营活动产生的现金流净额间接法
214 |
215 | *- 补充变量标签
216 | label var YEAR "观测年份"
217 |
218 | *- 保存数据
219 | label data "现金流量表数据间接法 - From Shutter Zor"
220 | save "DataB-Hub/Data5.dta", replace
221 |
222 | *- 合并资产负债表、利润表、现金流量表数据,并计算相关变量
223 | // 2024/12/31 开始,取消 “仅保留合并上的结果,即取消 keep if _merge == 3”
224 | use "DataB-Hub/Data2.dta", clear
225 |
226 | *- 合并利润表
227 | merge 1:1 STKCD YEAR using "DataB-Hub/Data3.dta"
228 | drop _merge
229 |
230 | *- 合并现金流量表直接法
231 | merge 1:1 STKCD YEAR using "DataB-Hub/Data4.dta"
232 | drop _merge
233 |
234 | *- 合并现金流量表间接法
235 | merge 1:1 STKCD YEAR using "DataB-Hub/Data5.dta"
236 | drop _merge
237 |
238 | *- 生成变量 - 现金流状况 CFO
239 | destring 经营活动产生的现金流净额直接法 经营活动产生的现金流净额间接法, replace
240 | gen CFO1 = 经营活动产生的现金流净额直接法 / 总资产
241 | gen CFO2 = 经营活动产生的现金流净额间接法 / 总资产
242 |
243 | *- 生成变量 - 总资产收益率 ROA
244 | destring 净利润, replace
245 | gen ROA = 净利润 / 总资产
246 |
247 | *- 生成变量 - 净资产收益率 ROE
248 | destring 所有者权益, replace
249 | gen ROE = 净利润 / 所有者权益
250 |
251 | *- 生成变量 - 总资产周转率 TAT
252 | gen TAT = 营业收入 / 总资产
253 |
254 | *- 保留有效变量
255 | keep STKCD STKNM YEAR CFO1 CFO2 GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT
256 |
257 | *- 补充变量标签
258 | label var CFO1 "现金流状况-直接法"
259 | label var CFO2 "现金流状况-间接法"
260 | label var ROA "总资产收益率"
261 | label var ROE "净资产收益率"
262 | label var TAT "总资产周转率"
263 |
264 | *- 排序与保存数据
265 | order STKCD STKNM YEAR CFO1 CFO2 GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT
266 | label data "财务报表相关变量9类10个 - From Shutter Zor"
267 | save "DataB-Hub/Data6.dta", replace
268 |
269 | /* 本部分生成的 Data6 用于后续合并 */
270 | /* CFO GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT */
271 |
272 | // 结束时间记录:
273 | dis "`c(current_date)' `c(current_time)'"
274 | ********************************************************************************
275 |
276 |
277 |
278 | ********************************************************************************
279 | // 开始时间记录:
280 | dis "`c(current_date)' `c(current_time)'"
281 |
282 | *- 清洗治理结构相关数据
283 | /* 包含变量:BALANCE BOARD INDBOARD MHOLD TOP1 DUAL */
284 |
285 | *- 股东股本相关数据
286 | /* 包含变量:BALANCE TOP1 */
287 |
288 | *- 股东股本相关数据 - 1
289 | import excel using "DataA-Original/HLD_Shareholders.xlsx", first clear
290 | labone, nrow(1 2) concat("_")
291 | drop in 1/2
292 |
293 | *- 仅保留年报数据
294 | keep if substr(Reptdt,6,2) == "12"
295 |
296 | *- 重命名变量
297 | rename Stkcd STKCD
298 |
299 | *- 生成变量 - 观测年份
300 | gen YEAR = real(substr(Reptdt,1,4))
301 |
302 | *- 生成变量 - 第一大股东持股数量 TOP1
303 | destring S0304a, replace
304 | bys STKCD YEAR: egen TOP1 = max(S0304a)
305 |
306 | *- 生成变量 - 股权制衡度 BALANCE
307 | bys STKCD YEAR: egen TOP2_5 = sum(S0304a) if S0306a=="2" | S0306a=="3" | S0306a=="4" | S0306a=="5" // 生成第二到第五大股东持股比例之和
308 | gen BALANCE = TOP2_5 / TOP1
309 |
310 | *- 保留有效样本
311 | destring S0306a, replace
312 | drop if S0306a > 5
313 | drop if TOP2_5 == .
314 | duplicates drop STKCD YEAR, force
315 |
316 | *- 保留有效变量
317 | keep STKCD YEAR BALANCE TOP1
318 |
319 | *- 补充变量标签
320 | label var YEAR "观测年份"
321 | label var TOP1 "第一大股东持股数量"
322 | label var BALANCE "股权制衡度"
323 |
324 | *- 排序与保存数据
325 | order STKCD YEAR BALANCE TOP1
326 | label data "股东股本相关数据-1 - From Shutter Zor"
327 | save "DataB-Hub/Data7-1.dta", replace
328 |
329 | *- 股东股本相关数据 - 2
330 | import excel using "DataA-Original/HLD_Shareholders1.xlsx", first clear
331 | labone, nrow(1 2) concat("_")
332 | drop in 1/2
333 |
334 | *- 仅保留年报数据
335 | keep if substr(Reptdt,6,2) == "12"
336 |
337 | *- 重命名变量
338 | rename Stkcd STKCD
339 |
340 | *- 生成变量 - 观测年份
341 | gen YEAR = real(substr(Reptdt,1,4))
342 |
343 | *- 生成变量 - 第一大股东持股数量 TOP1
344 | destring S0304a, replace
345 | bys STKCD YEAR: egen TOP1 = max(S0304a)
346 |
347 | *- 生成变量 - 股权制衡度 BALANCE
348 | bys STKCD YEAR: egen TOP2_5 = sum(S0304a) if S0306a=="2" | S0306a=="3" | S0306a=="4" | S0306a=="5" // 生成第二到第五大股东持股比例之和
349 | gen BALANCE = TOP2_5 / TOP1
350 |
351 | *- 保留有效样本
352 | destring S0306a, replace
353 | drop if S0306a > 5
354 | drop if TOP2_5 == .
355 | duplicates drop STKCD YEAR, force
356 |
357 | *- 保留有效变量
358 | keep STKCD YEAR BALANCE TOP1
359 |
360 | *- 补充变量标签
361 | label var YEAR "观测年份"
362 | label var TOP1 "第一大股东持股数量"
363 | label var BALANCE "股权制衡度"
364 |
365 | *- 排序与保存数据
366 | order STKCD YEAR BALANCE TOP1
367 | label data "股东股本相关数据-2 - From Shutter Zor"
368 | save "DataB-Hub/Data7-2.dta", replace
369 |
370 | *- 股东股本相关数据 - 3
371 | import excel using "DataA-Original/HLD_Shareholders2.xlsx", first clear
372 | labone, nrow(1 2) concat("_")
373 | drop in 1/2
374 |
375 | *- 仅保留年报数据
376 | keep if substr(Reptdt,6,2) == "12"
377 |
378 | *- 重命名变量
379 | rename Stkcd STKCD
380 |
381 | *- 生成变量 - 观测年份
382 | gen YEAR = real(substr(Reptdt,1,4))
383 |
384 | *- 生成变量 - 第一大股东持股数量 TOP1
385 | destring S0304a, replace
386 | bys STKCD YEAR: egen TOP1 = max(S0304a)
387 |
388 | *- 生成变量 - 股权制衡度 BALANCE
389 | bys STKCD YEAR: egen TOP2_5 = sum(S0304a) if S0306a=="2" | S0306a=="3" | S0306a=="4" | S0306a=="5" // 生成第二到第五大股东持股比例之和
390 | gen BALANCE = TOP2_5 / TOP1
391 |
392 | *- 保留有效样本
393 | destring S0306a, replace
394 | drop if S0306a > 5
395 | drop if TOP2_5 == .
396 | duplicates drop STKCD YEAR, force
397 |
398 | *- 保留有效变量
399 | keep STKCD YEAR BALANCE TOP1
400 |
401 | *- 补充变量标签
402 | label var YEAR "观测年份"
403 | label var TOP1 "第一大股东持股数量"
404 | label var BALANCE "股权制衡度"
405 |
406 | *- 排序与保存数据
407 | order STKCD YEAR BALANCE TOP1
408 | label data "股东股本相关数据-3 - From Shutter Zor"
409 | save "DataB-Hub/Data7-3.dta", replace
410 |
411 | *- 合并股东股本相关数据
412 | use "DataB-Hub/Data7-1.dta", clear
413 | append using "DataB-Hub/Data7-2.dta"
414 | append using "DataB-Hub/Data7-3.dta"
415 | label data "股东股本相关数据 - From Shutter Zor"
416 | save "DataB-Hub/Data7.dta", replace
417 | erase "DataB-Hub/Data7-1.dta"
418 | erase "DataB-Hub/Data7-2.dta"
419 |
420 | *- 高管动态相关数据
421 | /* 包含变量:BOARD INDBOARD MHOLD */
422 |
423 | *- 高管动态数据
424 | import excel using "DataA-Original/CG_ManagerShareSalary.xlsx", first clear
425 | labone, nrow(1 2) concat("_")
426 | drop in 1/2
427 |
428 | *- 仅保留年末在职人员样本
429 | keep if StatisticalCaliber == "1"
430 |
431 | *- 重命名变量
432 | rename Symbol STKCD
433 |
434 | *- 生成变量 - 观测年份 YEAR
435 | gen YEAR = real(substr(Enddate,1,4))
436 |
437 | *- 生成变量 - 董事规模 BOARD
438 | destring DirectorNumber, replace
439 | gen BOARD = ln(DirectorNumber)
440 |
441 | *- 生成变量 - 独立董事占比 INDBOARD
442 | destring IndependentDirectorNumber, replace
443 | gen INDBOARD = IndependentDirectorNumber / DirectorNumber
444 |
445 | *- 管理层持股数量
446 | destring Holdshares, replace
447 |
448 | *- 保留有效变量
449 | keep STKCD YEAR BOARD INDBOARD Holdshares
450 |
451 | *- 补充变量标签
452 | label var YEAR "观测年份"
453 | label var BOARD "董事规模"
454 | label var INDBOARD "独立董事占比"
455 |
456 | *- 保存数据
457 | label data "高管动态相关数据-1 - From Shutter Zor"
458 | save "DataB-Hub/Data8-1.dta", replace
459 |
460 | *- 股本结构文件
461 | import excel using "DataA-Original/CG_Capchg.xlsx", first clear
462 | labone, nrow(1 2) concat("_")
463 | drop in 1/2
464 |
465 | *- 重命名变量
466 | rename Stkcd STKCD
467 |
468 | *- 生成变量 - 观测年份 YEAR
469 | gen YEAR = real(substr(Reptdt,1,4))
470 |
471 | *- 补充变量标签
472 | label var YEAR "观测年份"
473 |
474 | *- 保留有效变量
475 | keep STKCD YEAR Nshrttl
476 |
477 | *- 保存数据
478 | label data "高管动态相关数据-2 - From Shutter Zor"
479 | save "DataB-Hub/Data8-2.dta", replace
480 |
481 | *- 合并高管动态与股本结构,主要是计算MHOLD
482 | // 2024/12/31 开始,取消 “仅保留合并上的结果,即取消 keep if _merge == 3”
483 | use "DataB-Hub/Data8-1.dta", clear
484 | merge 1:1 STKCD YEAR using "DataB-Hub/Data8-2.dta"
485 | drop _merge
486 |
487 | *- 生成变量 - 管理层持股比例 MHOLD
488 | destring Nshrttl, replace
489 | gen MHOLD = Holdshares / Nshrttl
490 |
491 | *- 保留有效变量
492 | keep STKCD YEAR BOARD INDBOARD MHOLD
493 |
494 | *- 补充变量标签
495 | label var MHOLD "管理层持股比例"
496 |
497 | *- 排序与保存数据
498 | order STKCD YEAR BOARD INDBOARD MHOLD
499 | label data "高管动态与股本结构相关数据 - From Shutter Zor"
500 | save "DataB-Hub/Data8.dta", replace
501 | erase "DataB-Hub/Data8-1.dta"
502 | erase "DataB-Hub/Data8-2.dta"
503 |
504 | *- 高管人数、持股相关数据
505 | /* 包含变量:DUAL */
506 | import excel using "DataA-Original/CG_Ybasic.xlsx", first clear
507 | labone, nrow(1 2) concat("_")
508 | drop in 1/2
509 |
510 | *- 重命名变量
511 | rename Stkcd STKCD
512 |
513 | *- 生成变量 - 观测年份 YEAR
514 | gen YEAR = real(substr(Reptdt,1,4))
515 |
516 | *- 生成变量 - 两职合一 DUAL
517 | destring Y1001b, replace
518 | rename Y1001b DUAL
519 | replace DUAL = 0 if DUAL == 2
520 |
521 | *- 保留有效变量
522 | keep STKCD YEAR DUAL
523 |
524 | *- 补充变量标签
525 | label var YEAR "观测年份"
526 | label var DUAL "两职合一"
527 |
528 | *- 保存数据
529 | label data "高管人数、持股相关数据 - From Shutter Zor"
530 | save "DataB-Hub/Data9.dta", replace
531 |
532 | *- 合并治理结构相关数据
533 | // 2024/12/31 开始,取消 “仅保留合并上的结果,即取消 keep if _merge == 3”
534 | use "DataB-Hub/Data7.dta", clear
535 | merge 1:1 STKCD YEAR using "DataB-Hub/Data8.dta"
536 | drop _merge
537 | merge 1:1 STKCD YEAR using "DataB-Hub/Data9.dta"
538 | drop _merge
539 |
540 | *- 排序与保存数据
541 | order STKCD YEAR BALANCE BOARD INDBOARD MHOLD TOP1 DUAL
542 | label data "治理结构相关变量6个 - From Shutter Zor"
543 | save "DataB-Hub/Data10.dta", replace
544 |
545 | /* 本部分生成的 Data10 用于后续合并 */
546 | /* BALANCE BOARD INDBOARD MHOLD TOP1 DUAL */
547 |
548 | // 结束时间记录:
549 | dis "`c(current_date)' `c(current_time)'"
550 | ********************************************************************************
551 |
552 |
553 |
554 | ********************************************************************************
555 | // 开始时间记录:
556 | dis "`c(current_date)' `c(current_time)'"
557 |
558 | *- 清洗财务指标分析相关数据
559 | /* 包含变量:BM TobinQ */
560 |
561 | import excel using "DataA-Original/FI_T10.xlsx", first clear
562 | labone, nrow(1 2) concat("_")
563 | drop in 1/2
564 |
565 | *- 仅保留年报数据
566 | keep if substr(Accper,6,2) == "12"
567 |
568 | *- 重命名变量
569 | rename (Stkcd ShortName F100901A F100902A F100903A F100904A F101001A F101002A) (STKCD STKNM TobinQ1 TobinQ2 TobinQ3 TobinQ4 BM1 BM2)
570 |
571 | *- 生成变量 - 观测年份 YEAR
572 | gen YEAR = real(substr(Accper,1,4))
573 |
574 | *- 生成变量 - 账面市值比 BM 与 托宾Q值 TobinQ
575 | destring BM* TobinQ*, replace
576 |
577 | *- 保留有效变量
578 | keep STKCD YEAR BM* TobinQ*
579 |
580 | *- 补充变量标签
581 | label var YEAR "观测年份"
582 |
583 | *- 保存数据
584 | label data "财务指标分析相关变量2个"
585 | save "DataB-Hub/Data11.dta", replace
586 |
587 | /* 本部分生成的 Data11 用于后续合并 */
588 | /* BM TobinQ */
589 |
590 | // 结束时间记录:
591 | dis "`c(current_date)' `c(current_time)'"
592 | ********************************************************************************
593 |
594 |
595 |
596 | ********************************************************************************
597 | // 开始时间记录:
598 | dis "`c(current_date)' `c(current_time)'"
599 |
600 | *- 清洗机构投资者相关数据
601 | /* 包含变量:INSTITUTION */
602 |
603 | import excel using "DataA-Original/INI_HolderSystematics.xlsx", first clear
604 | labone, nrow(1 2) concat("_")
605 | drop in 1/2
606 |
607 | *- 仅保留年报数据
608 | keep if substr(EndDate,6,2) == "12"
609 |
610 | *- 重命名变量
611 | rename (Symbol InsInvestorProp InsInvestorProp1) (STKCD INSTITUTION1 INSTITUTION2)
612 |
613 | *- 生成变量 - 观测年份 YEAR
614 | gen YEAR = real(substr(EndDate,1,4))
615 |
616 | *- 生成变量 - 机构投资者比例 INSTITUTION
617 | destring INSTITUTION*, replace
618 |
619 | *- 保留有效变量
620 | keep STKCD YEAR INSTITUTION*
621 |
622 | *- 补充变量标签
623 | label var YEAR "观测年份"
624 |
625 | *- 保存数据
626 | label data "机构投资者相关变量1个"
627 | save "DataB-Hub/Data12.dta", replace
628 |
629 | /* 本部分生成的 Data12 用于后续合并 */
630 | /* INSTITUTION */
631 |
632 | // 结束时间记录:
633 | dis "`c(current_date)' `c(current_time)'"
634 | ********************************************************************************
635 |
636 |
637 |
638 | ********************************************************************************
639 | // 开始时间记录:
640 | dis "`c(current_date)' `c(current_time)'"
641 |
642 | *- 清洗分析师预测相关数据
643 | /* 包含变量:AUDIT */
644 |
645 | import excel using "DataA-Original/AF_CFEATUREPROFILE.xlsx", first clear
646 | labone, nrow(1 2) concat("_")
647 | drop in 1/2
648 |
649 | *- 仅保留年报数据
650 | keep if substr(Accper,6,2) == "12"
651 |
652 | *- 重命名变量
653 | rename (Stknmec Stkcd) (STKNM STKCD)
654 |
655 | *- 生成变量 - 观测年份 YEAR
656 | gen YEAR = real(substr(Accper,1,4))
657 |
658 | *- 生成变量 - 是否由四大会计师事务所审计 AUDIT
659 | gen AUDIT = 1 if Big4 == "Y"
660 | replace AUDIT = 0 if Big4 == "N"
661 |
662 | *- 保留有效变量
663 | keep STKCD YEAR AUDIT
664 |
665 | *- 补充变量标签
666 | label var YEAR "观测年份"
667 | label var AUDIT "是否由四大会计师事务所审计"
668 |
669 | *- 保存数据
670 | duplicates drop STKCD YEAR, force
671 | label data "分析师预测相关变量1个"
672 | save "DataB-Hub/Data13.dta", replace
673 |
674 | /* 本部分生成的 Data13 用于后续合并 */
675 | /* AUDIT */
676 |
677 | // 结束时间记录:
678 | dis "`c(current_date)' `c(current_time)'"
679 | ********************************************************************************
680 |
681 |
682 |
683 | ********************************************************************************
684 | // 开始时间记录:
685 | dis "`c(current_date)' `c(current_time)'"
686 |
687 | *- 清洗财务报告审计意见相关数据
688 | /* 包含变量:OPINION */
689 |
690 | import excel using "DataA-Original/FIN_Audit.xlsx", first clear
691 | labone, nrow(1 2) concat("_")
692 | drop in 1/2
693 |
694 | *- 仅保留年报数据
695 | keep if substr(Accper,6,2) == "12"
696 |
697 | *- 重命名变量
698 | rename (Stkcd Stknme) (STKCD STKNM)
699 |
700 | *- 生成变量 - 观测年份 YEAR
701 | gen YEAR = real(substr(Accper,1,4))
702 |
703 | *- 生成变量 - 是否由四大会计师事务所审计 AUDIT
704 | gen OPINION = 1 if Audittyp == "标准无保留意见"
705 | replace OPINION = 0 if Audittyp != "标准无保留意见"
706 |
707 | *- 保留有效变量
708 | keep STKCD YEAR OPINION
709 |
710 | *- 补充变量标签
711 | label var YEAR "观测年份"
712 | label var OPINION "是否标准无保留意见"
713 |
714 | *- 保存数据
715 | label data "财务报告审计意见相关变量1个"
716 | save "DataB-Hub/Data14.dta", replace
717 |
718 | /* 本部分生成的 Data14 用于后续合并 */
719 | /* OPINION */
720 |
721 | // 结束时间记录:
722 | dis "`c(current_date)' `c(current_time)'"
723 | ********************************************************************************
724 |
725 |
726 |
727 | ********************************************************************************
728 | // 开始时间记录:
729 | dis "`c(current_date)' `c(current_time)'"
730 |
731 | *- 清洗股权性质相关数据
732 | /* 包含变量:SOE */
733 |
734 | import excel using "DataA-Original/EN_EquityNatureAll.xlsx", first clear
735 | labone, nrow(1 2) concat("_")
736 | drop in 1/2
737 |
738 | *- 仅保留年报数据
739 | keep if substr(EndDate,6,2) == "12"
740 |
741 | *- 重命名变量
742 | rename (Symbol ShortName) (STKCD STKNM)
743 |
744 | *- 生成变量 - 观测年份 YEAR
745 | gen YEAR = real(substr(EndDate,1,4))
746 |
747 | *- 生成变量 - 是否为国企 SOE
748 | gen SOE = 1 if EquityNature == "国企"
749 | replace SOE = 0 if EquityNature != "国企"
750 |
751 | *- 保留有效变量
752 | keep STKCD YEAR SOE
753 |
754 | *- 补充变量标签
755 | label var YEAR "观测年份"
756 | label var SOE "是否为国企"
757 |
758 | *- 保存数据
759 | label data "股权性质相关变量1个"
760 | save "DataB-Hub/Data15.dta", replace
761 |
762 | /* 本部分生成的 Data15 用于后续合并 */
763 | /* SOE */
764 |
765 | // 结束时间记录:
766 | dis "`c(current_date)' `c(current_time)'"
767 | ********************************************************************************
768 |
769 |
770 |
771 |
772 |
773 | ********************************************************************************
774 | // 开始时间记录:
775 | dis "`c(current_date)' `c(current_time)'"
776 |
777 | /* 至此完成了所有数据变量的计算,接下来需要将所有内容完全合并 */
778 | /* 文件位置:DataB-Hub
779 | Data1.dta: STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE
780 | Data6.dta: CFO GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT
781 | Data10.dta: BALANCE BOARD INDBOARD MHOLD TOP1 DUAL
782 | Data11.dta: BM TobinQ
783 | Data12.dta: INSTITUTION
784 | Data13.dta: AUDIT
785 | Data14.dta: OPINION
786 | Data15.dta: SOE
787 | 总计: 33 种变量,其中 AGE、BM、CFO、TobinQ 含有多类
788 | */
789 |
790 | *- 最终合并
791 | // 2024/12/31 开始,取消 “仅保留合并上的结果,即取消 keep if _merge == 3”
792 | use "DataB-Hub/Data1.dta", clear
793 | merge 1:1 STKCD YEAR using "DataB-Hub/Data6.dta"
794 | drop _merge
795 | merge 1:1 STKCD YEAR using "DataB-Hub/Data10.dta"
796 | drop _merge
797 | merge 1:1 STKCD YEAR using "DataB-Hub/Data11.dta"
798 | drop _merge
799 | merge 1:1 STKCD YEAR using "DataB-Hub/Data12.dta"
800 | drop _merge
801 | merge 1:1 STKCD YEAR using "DataB-Hub/Data13.dta"
802 | drop _merge
803 | merge 1:1 STKCD YEAR using "DataB-Hub/Data14.dta"
804 | drop _merge
805 | merge 1:1 STKCD YEAR using "DataB-Hub/Data15.dta"
806 | drop _merge
807 |
808 | *- 排序与保存数据
809 | order STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE1 AGE2 BALANCE BM1 BM2 BOARD CFO1 CFO2 GROWTH INDBOARD INSTITUTION1 INSTITUTION2 LEV MFEE MHOLD OCCUPY ROA ROE SIZE TAT TobinQ1 TobinQ2 TobinQ3 TobinQ4 TOP1 AUDIT DUAL OPINION SOE
810 |
811 | label data "Commonly used control variables (2001-2023) by Shutter Zor (Shutter_Z@outlook)."
812 | save ControlVarsDetail.dta, replace
813 |
814 | // 结束时间记录:
815 | dis "`c(current_date)' `c(current_time)'"
816 | ********************************************************************************
817 | log close _all
818 |
819 |
820 |
--------------------------------------------------------------------------------
/CSMAR CtrlVars Cleaning Log.smcl:
--------------------------------------------------------------------------------
1 | {smcl}
2 | {com}{sf}{ul off}{txt}{.-}
3 | name: {res}ShutterZorADXMU20241231
4 | {txt}log: {res}F:\Doctor\GitHub Repos\Commonly-Used-Control-Variables\CSMAR CtrlVars Cleaning Log.smcl
5 | {txt}log type: {res}smcl
6 | {txt}opened on: {res}31 Dec 2024, 12:08:55
7 | {txt}
8 | {com}. * =============================================================
9 | . /* Author Information */
10 | .
11 | . * Name: Shutter Zor(左祥太)
12 | . * Email: Shutter_Z@outlook.com
13 | . * Affiliation: Accounting Department, Xiamen University
14 | . * Date: 2024/12/31
15 | . * Version: V3.0
16 | .
17 | . * =============================================================
18 | .
19 | .
20 | .
21 | . /* 常用控制变量数据清洗教程(ControlVarsDetail.dta)*/
22 | . /* 说明:本次样本为所有上市公司2001-2023(含2001与2023)的数据 */
23 | .
24 | .
25 | .
26 | . ********************************************************************************
27 | . // 开始时间记录:
28 | . dis "`c(current_date)' `c(current_time)'"
29 | {res}31 Dec 2024 12:08:55
30 | {txt}
31 | {com}.
32 | . *- 清洗上市公司基本信息数据
33 | . /* 包含变量:STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE */
34 | .
35 | . import excel using "DataA-Original/STK_LISTEDCOINFOANL.xlsx", first clear
36 | {res}{text}(16 vars, 62,358 obs)
37 |
38 | {com}. labone, nrow(1 2) concat("_")
39 | {txt}
40 | {com}. drop in 1/2
41 | {txt}(2 observations deleted)
42 |
43 | {com}.
44 | . *- 生成变量 - 观测年份
45 | . gen YEAR = substr(EndDate,1,4)
46 | {txt}
47 | {com}. destring YEAR, replace
48 | {txt}YEAR: all characters numeric; {res}replaced {txt}as {res}int
49 | {txt}
50 | {com}.
51 | . *- 生成变量 - 成立年份至观测年份的 AGE1
52 | . gen EstablishYear = substr(EstablishDate,1,4)
53 | {txt}(10 missing values generated)
54 |
55 | {com}. destring EstablishYear, replace
56 | {txt}EstablishYear: all characters numeric; {res}replaced {txt}as {res}int
57 | {txt}(10 missing values generated)
58 | {res}{txt}
59 | {com}. gen AGE1 = YEAR - EstablishYear
60 | {txt}(10 missing values generated)
61 |
62 | {com}.
63 | . *- 生成变量 - 上市年份至观测年份的 AGE2
64 | . gen ListingYear = substr(LISTINGDATE,1,4)
65 | {txt}
66 | {com}. destring ListingYear, replace
67 | {txt}ListingYear: all characters numeric; {res}replaced {txt}as {res}int
68 | {txt}
69 | {com}. gen AGE2 = YEAR - ListingYear
70 | {txt}
71 | {com}. drop if AGE2 < 0 // 去掉部分不合理的观测样本
72 | {txt}(1,597 observations deleted)
73 |
74 | {com}.
75 | . *- 生成变量 - 股票市场板块 MARKET
76 | . gen MARKET = "深证主板A股" if substr(Symbol,1,2) == "00"
77 | {txt}(37,132 missing values generated)
78 |
79 | {com}. replace MARKET = "深证创业板" if substr(Symbol,1,2) == "30"
80 | {txt}(9,430 real changes made)
81 |
82 | {com}. replace MARKET = "深证B股" if substr(Symbol,1,2) == "20"
83 | {txt}(262 real changes made)
84 |
85 | {com}. replace MARKET = "上证主板A股" if substr(Symbol,1,2) == "60"
86 | {txt}(24,993 real changes made)
87 |
88 | {com}. replace MARKET = "上证科创板" if substr(Symbol,1,2) == "68"
89 | {txt}(1,729 real changes made)
90 |
91 | {com}. replace MARKET = "上证B股" if substr(Symbol,1,2) == "90"
92 | {txt}(194 real changes made)
93 |
94 | {com}. replace MARKET = "北证A股" if substr(Symbol,1,2) == "43" | substr(Symbol,1,2) == "83" | substr(Symbol,1,2) == "87"
95 | {txt}(524 real changes made)
96 |
97 | {com}.
98 | . *- 重命名变量
99 | . rename (Symbol ShortName IndustryName IndustryCode PROVINCECODE PROVINCE CITYCODE CITY LISTINGSTATE) (STKCD STKNM INDNM INDCD PROVCD PROVNM CITYCD CITYNM STATE)
100 | {res}{txt}
101 | {com}.
102 | . *- 保留有效变量
103 | . keep STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE1 AGE2
104 | {txt}
105 | {com}.
106 | . *- 补充变量标签
107 | . label var YEAR "观测年份"
108 | {txt}
109 | {com}. label var MARKET "股票市场板块"
110 | {txt}
111 | {com}. label var AGE1 "从成立年份到观测年份的年龄"
112 | {txt}
113 | {com}. label var AGE2 "从上市年份到观测年份的年龄"
114 | {txt}
115 | {com}.
116 | . *- 排序与保存数据
117 | . order STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE1 AGE2
118 | {txt}
119 | {com}. label data "基本信息相关变量11+年龄 - From Shutter Zor"
120 | {txt}
121 | {com}. save "DataB-Hub/Data1.dta", replace
122 | {txt}file DataB-Hub/Data1.dta saved
123 |
124 | {com}.
125 | . /* 本部分生成的 Data1 用于后续合并 */
126 | . /* STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE */
127 | .
128 | . // 结束时间记录:
129 | . dis "`c(current_date)' `c(current_time)'"
130 | {res}31 Dec 2024 12:09:07
131 | {txt}
132 | {com}. ********************************************************************************
133 | .
134 | .
135 | .
136 | . ********************************************************************************
137 | . // 开始时间记录:
138 | . dis "`c(current_date)' `c(current_time)'"
139 | {res}31 Dec 2024 12:09:07
140 | {txt}
141 | {com}.
142 | . *- 清洗财务报表相关数据
143 | . /* 包含变量:CFO GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT */
144 | .
145 | . *- 资产负债表
146 | . import excel using "DataA-Original/FS_Combas.xlsx", first clear
147 | {res}{text}(8 vars, 582,512 obs)
148 |
149 | {com}. labone, nrow(1 2) concat("_")
150 | {txt}
151 | {com}. drop in 1/2
152 | {txt}(2 observations deleted)
153 |
154 | {com}.
155 | . *- 仅保留合并报表数据
156 | . keep if Typrep == "A" // A为合并报表,B为母公司报表
157 | {txt}(270,157 observations deleted)
158 |
159 | {com}.
160 | . *- 仅保留年报数据
161 | . keep if substr(Accper,6,2) == "12" // 12月的年报
162 | {txt}(247,234 observations deleted)
163 |
164 | {com}.
165 | . *- 重命名变量
166 | . rename (Stkcd ShortName A001121000 A001000000 A002000000 A003000000) (STKCD STKNM 其他应收款 总资产 总负债 所有者权益)
167 | {res}{txt}
168 | {com}.
169 | . *- 生成变量 - 观测年份
170 | . gen YEAR = real(substr(Accper,1,4))
171 | {txt}
172 | {com}.
173 | . *- 生成变量 - 资产负债率 LEV
174 | . destring 总负债 总资产, replace // 转为数值变量,方便计算
175 | {txt}总负债: all characters numeric; {res}replaced {txt}as {res}double
176 | {txt}总资产: all characters numeric; {res}replaced {txt}as {res}double
177 | {txt}
178 | {com}. gen LEV = 总负债 / 总资产
179 | {txt}(3 missing values generated)
180 |
181 | {com}.
182 | . *- 生成变量 - 大股东资金占用 OCCUPY
183 | . destring 其他应收款, replace
184 | {txt}其他应收款: all characters numeric; {res}replaced {txt}as {res}double
185 | {txt}(831 missing values generated)
186 | {res}{txt}
187 | {com}. gen OCCUPY = 其他应收款 / 总资产
188 | {txt}(834 missing values generated)
189 |
190 | {com}.
191 | . *- 生成变量 - 公司规模 SIZE
192 | . gen SIZE = ln(总资产)
193 | {txt}(3 missing values generated)
194 |
195 | {com}.
196 | . *- 保留有效变量
197 | . keep STKCD STKNM 总资产 所有者权益 YEAR LEV OCCUPY SIZE
198 | {txt}
199 | {com}.
200 | . *- 补充变量标签
201 | . label var YEAR "观测年份"
202 | {txt}
203 | {com}. label var LEV "资产负债率"
204 | {txt}
205 | {com}. label var OCCUPY "大股东资金占用"
206 | {txt}
207 | {com}. label var SIZE "公司规模"
208 | {txt}
209 | {com}.
210 | . *- 保存数据
211 | . label data "资产负债表数据 - From Shutter Zor"
212 | {txt}
213 | {com}. save "DataB-Hub/Data2.dta", replace
214 | {txt}file DataB-Hub/Data2.dta saved
215 |
216 | {com}.
217 | . *- 利润表
218 | . import excel using "DataA-Original/FS_Comins.xlsx", first clear
219 | {res}{text}(7 vars, 581,448 obs)
220 |
221 | {com}. labone, nrow(1 2) concat("_")
222 | {txt}
223 | {com}. drop in 1/2
224 | {txt}(2 observations deleted)
225 |
226 | {com}.
227 | . *- 仅保留合并报表数据
228 | . keep if Typrep == "A" // A为合并报表,B为母公司报表
229 | {txt}(270,478 observations deleted)
230 |
231 | {com}.
232 | . *- 仅保留年报数据
233 | . keep if substr(Accper,6,2) == "12" // 12月的年报
234 | {txt}(246,348 observations deleted)
235 |
236 | {com}.
237 | . *- 重命名变量
238 | . rename (Stkcd ShortName B001101000 B001210000 B002000000) (STKCD STKNM 营业收入 管理费用 净利润)
239 | {res}{txt}
240 | {com}.
241 | . *- 生成变量 - 观测年份
242 | . gen YEAR = real(substr(Accper,1,4))
243 | {txt}
244 | {com}.
245 | . *- 生成变量 - 营业收入增长率 GROWTH
246 | . destring 营业收入, replace
247 | {txt}营业收入: all characters numeric; {res}replaced {txt}as {res}double
248 | {txt}(1119 missing values generated)
249 | {res}{txt}
250 | {com}. egen STKID = group(STKCD)
251 | {txt}
252 | {com}. xtset STKID YEAR
253 | {res}{txt}{col 8}panel variable: {res}STKID (unbalanced)
254 | {txt}{col 9}time variable: {res}{col 25}YEAR, 2001 to 2023, but with a gap
255 | {txt}{col 17}delta: {res}1 unit
256 | {txt}
257 | {com}. bys STKID: gen GROWTH = (营业收入 - L.营业收入) / L.营业收入
258 | {txt}(6,791 missing values generated)
259 |
260 | {com}.
261 | . *- 生成变量 - 管理层费用率 MFEE
262 | . destring 管理费用, replace
263 | {txt}管理费用: all characters numeric; {res}replaced {txt}as {res}double
264 | {txt}(888 missing values generated)
265 | {res}{txt}
266 | {com}. gen MFEE = 管理费用 / 营业收入
267 | {txt}(1,155 missing values generated)
268 |
269 | {com}.
270 | . *- 保留有效变量
271 | . keep STKCD STKNM YEAR 营业收入 净利润 GROWTH MFEE
272 | {txt}
273 | {com}.
274 | . *- 补充变量标签
275 | . label var YEAR "观测年份"
276 | {txt}
277 | {com}. label var GROWTH "营业收入增长率"
278 | {txt}
279 | {com}. label var MFEE "管理层费用率"
280 | {txt}
281 | {com}.
282 | . *- 保存数据
283 | . label data "利润表数据 - From Shutter Zor"
284 | {txt}
285 | {com}. save "DataB-Hub/Data3.dta", replace
286 | {txt}file DataB-Hub/Data3.dta saved
287 |
288 | {com}.
289 | . *- 现金流量表 - 直接法
290 | . import excel using "DataA-Original/FS_Comscfd.xlsx", first clear
291 | {res}{text}(5 vars, 566,394 obs)
292 |
293 | {com}. labone, nrow(1 2) concat("_")
294 | {txt}
295 | {com}. drop in 1/2
296 | {txt}(2 observations deleted)
297 |
298 | {com}.
299 | . *- 仅保留合并报表数据
300 | . keep if Typrep == "A" // A为合并报表,B为母公司报表
301 | {txt}(264,935 observations deleted)
302 |
303 | {com}.
304 | . *- 仅保留年报数据
305 | . keep if substr(Accper,6,2) == "12" // 12月的年报
306 | {txt}(236,341 observations deleted)
307 |
308 | {com}.
309 | . *- 重命名变量
310 | . rename (Stkcd ShortName C001000000) (STKCD STKNM 经营活动产生的现金流净额直接法)
311 | {res}{txt}
312 | {com}.
313 | . *- 生成变量 - 观测年份
314 | . gen YEAR = real(substr(Accper,1,4))
315 | {txt}
316 | {com}.
317 | . *- 保留有效变量
318 | . keep STKCD STKNM YEAR 经营活动产生的现金流净额直接法
319 | {txt}
320 | {com}.
321 | . *- 补充变量标签
322 | . label var YEAR "观测年份"
323 | {txt}
324 | {com}.
325 | . *- 保存数据
326 | . label data "现金流量表数据直接法 - From Shutter Zor"
327 | {txt}
328 | {com}. save "DataB-Hub/Data4.dta", replace
329 | {txt}file DataB-Hub/Data4.dta saved
330 |
331 | {com}.
332 | . *- 现金流量表 - 间接法
333 | . import excel using "DataA-Original/FS_Comscfi.xlsx", first clear
334 | {res}{text}(5 vars, 286,924 obs)
335 |
336 | {com}. labone, nrow(1 2) concat("_")
337 | {txt}
338 | {com}. drop in 1/2
339 | {txt}(2 observations deleted)
340 |
341 | {com}.
342 | . *- 仅保留合并报表数据
343 | . keep if Typrep == "A" // A为合并报表,B为母公司报表
344 | {txt}(91,342 observations deleted)
345 |
346 | {com}.
347 | . *- 仅保留年报数据
348 | . keep if substr(Accper,6,2) == "12" // 12月的年报
349 | {txt}(130,521 observations deleted)
350 |
351 | {com}.
352 | . *- 重命名变量
353 | . rename (Stkcd ShortName D000100000) (STKCD STKNM 经营活动产生的现金流净额间接法)
354 | {res}{txt}
355 | {com}.
356 | . *- 生成变量 - 观测年份
357 | . gen YEAR = real(substr(Accper,1,4))
358 | {txt}
359 | {com}.
360 | . *- 保留有效变量
361 | . keep STKCD STKNM YEAR 经营活动产生的现金流净额间接法
362 | {txt}
363 | {com}.
364 | . *- 补充变量标签
365 | . label var YEAR "观测年份"
366 | {txt}
367 | {com}.
368 | . *- 保存数据
369 | . label data "现金流量表数据间接法 - From Shutter Zor"
370 | {txt}
371 | {com}. save "DataB-Hub/Data5.dta", replace
372 | {txt}file DataB-Hub/Data5.dta saved
373 |
374 | {com}.
375 | . *- 合并资产负债表、利润表、现金流量表数据,并计算相关变量
376 | . // 2024/12/31 开始,取消 “仅保留合并上的结果,即取消 keep if _merge == 3”
377 | . use "DataB-Hub/Data2.dta", clear
378 | {txt}(资产负债表数据 - From Shutter Zor)
379 |
380 | {com}.
381 | . *- 合并利润表
382 | . merge 1:1 STKCD YEAR using "DataB-Hub/Data3.dta"
383 | {res}
384 | {txt}{col 5}Result{col 38}# of obs.
385 | {col 5}{hline 41}
386 | {col 5}not matched{col 30}{res} 499
387 | {txt}{col 9}from master{col 30}{res} 499{txt} (_merge==1)
388 | {col 9}from using{col 30}{res} 0{txt} (_merge==2)
389 |
390 | {col 5}matched{col 30}{res} 64,620{txt} (_merge==3)
391 | {col 5}{hline 41}
392 |
393 | {com}. drop _merge
394 | {txt}
395 | {com}.
396 | . *- 合并现金流量表直接法
397 | . merge 1:1 STKCD YEAR using "DataB-Hub/Data4.dta"
398 | {res}
399 | {txt}{col 5}Result{col 38}# of obs.
400 | {col 5}{hline 41}
401 | {col 5}not matched{col 30}{res} 3
402 | {txt}{col 9}from master{col 30}{res} 3{txt} (_merge==1)
403 | {col 9}from using{col 30}{res} 0{txt} (_merge==2)
404 |
405 | {col 5}matched{col 30}{res} 65,116{txt} (_merge==3)
406 | {col 5}{hline 41}
407 |
408 | {com}. drop _merge
409 | {txt}
410 | {com}.
411 | . *- 合并现金流量表间接法
412 | . merge 1:1 STKCD YEAR using "DataB-Hub/Data5.dta"
413 | {res}
414 | {txt}{col 5}Result{col 38}# of obs.
415 | {col 5}{hline 41}
416 | {col 5}not matched{col 30}{res} 64
417 | {txt}{col 9}from master{col 30}{res} 62{txt} (_merge==1)
418 | {col 9}from using{col 30}{res} 2{txt} (_merge==2)
419 |
420 | {col 5}matched{col 30}{res} 65,057{txt} (_merge==3)
421 | {col 5}{hline 41}
422 |
423 | {com}. drop _merge
424 | {txt}
425 | {com}.
426 | . *- 生成变量 - 现金流状况 CFO
427 | . destring 经营活动产生的现金流净额直接法 经营活动产生的现金流净额间接法, replace
428 | {txt}经营活动产生的现金流净额直接法: all characters numeric; {res}replaced {txt}as {res}double
429 | {txt}(5 missing values generated)
430 | {res}{txt}经营活动产生的现金流净额间接法: all characters numeric; {res}replaced {txt}as {res}double
431 | {txt}(63 missing values generated)
432 | {res}{txt}
433 | {com}. gen CFO1 = 经营活动产生的现金流净额直接法 / 总资产
434 | {txt}(8 missing values generated)
435 |
436 | {com}. gen CFO2 = 经营活动产生的现金流净额间接法 / 总资产
437 | {txt}(68 missing values generated)
438 |
439 | {com}.
440 | . *- 生成变量 - 总资产收益率 ROA
441 | . destring 净利润, replace
442 | {txt}净利润: all characters numeric; {res}replaced {txt}as {res}double
443 | {txt}(501 missing values generated)
444 | {res}{txt}
445 | {com}. gen ROA = 净利润 / 总资产
446 | {txt}(504 missing values generated)
447 |
448 | {com}.
449 | . *- 生成变量 - 净资产收益率 ROE
450 | . destring 所有者权益, replace
451 | {txt}所有者权益: all characters numeric; {res}replaced {txt}as {res}double
452 | {txt}(2 missing values generated)
453 | {res}{txt}
454 | {com}. gen ROE = 净利润 / 所有者权益
455 | {txt}(506 missing values generated)
456 |
457 | {com}.
458 | . *- 生成变量 - 总资产周转率 TAT
459 | . gen TAT = 营业收入 / 总资产
460 | {txt}(1,623 missing values generated)
461 |
462 | {com}.
463 | . *- 保留有效变量
464 | . keep STKCD STKNM YEAR CFO1 CFO2 GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT
465 | {txt}
466 | {com}.
467 | . *- 补充变量标签
468 | . label var CFO1 "现金流状况-直接法"
469 | {txt}
470 | {com}. label var CFO2 "现金流状况-间接法"
471 | {txt}
472 | {com}. label var ROA "总资产收益率"
473 | {txt}
474 | {com}. label var ROE "净资产收益率"
475 | {txt}
476 | {com}. label var TAT "总资产周转率"
477 | {txt}
478 | {com}.
479 | . *- 排序与保存数据
480 | . order STKCD STKNM YEAR CFO1 CFO2 GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT
481 | {txt}
482 | {com}. label data "财务报表相关变量9类10个 - From Shutter Zor"
483 | {txt}
484 | {com}. save "DataB-Hub/Data6.dta", replace
485 | {txt}file DataB-Hub/Data6.dta saved
486 |
487 | {com}.
488 | . /* 本部分生成的 Data6 用于后续合并 */
489 | . /* CFO GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT */
490 | .
491 | . // 结束时间记录:
492 | . dis "`c(current_date)' `c(current_time)'"
493 | {res}31 Dec 2024 12:10:53
494 | {txt}
495 | {com}. ********************************************************************************
496 | .
497 | .
498 | .
499 | . ********************************************************************************
500 | . // 开始时间记录:
501 | . dis "`c(current_date)' `c(current_time)'"
502 | {res}31 Dec 2024 12:10:53
503 | {txt}
504 | {com}.
505 | . *- 清洗治理结构相关数据
506 | . /* 包含变量:BALANCE BOARD INDBOARD MHOLD TOP1 DUAL */
507 | .
508 | . *- 股东股本相关数据
509 | . /* 包含变量:BALANCE TOP1 */
510 | .
511 | . *- 股东股本相关数据 - 1
512 | . import excel using "DataA-Original/HLD_Shareholders.xlsx", first clear
513 | {res}{text}(5 vars, 1,000,002 obs)
514 |
515 | {com}. labone, nrow(1 2) concat("_")
516 | {txt}
517 | {com}. drop in 1/2
518 | {txt}(2 observations deleted)
519 |
520 | {com}.
521 | . *- 仅保留年报数据
522 | . keep if substr(Reptdt,6,2) == "12"
523 | {txt}(716,644 observations deleted)
524 |
525 | {com}.
526 | . *- 重命名变量
527 | . rename Stkcd STKCD
528 | {res}{txt}
529 | {com}.
530 | . *- 生成变量 - 观测年份
531 | . gen YEAR = real(substr(Reptdt,1,4))
532 | {txt}
533 | {com}.
534 | . *- 生成变量 - 第一大股东持股数量 TOP1
535 | . destring S0304a, replace
536 | {txt}S0304a: all characters numeric; {res}replaced {txt}as {res}double
537 | {txt}
538 | {com}. bys STKCD YEAR: egen TOP1 = max(S0304a)
539 | {txt}
540 | {com}.
541 | . *- 生成变量 - 股权制衡度 BALANCE
542 | . bys STKCD YEAR: egen TOP2_5 = sum(S0304a) if S0306a=="2" | S0306a=="3" | S0306a=="4" | S0306a=="5" // 生成第二到第五大股东持股比例之和
543 | {txt}(170440 missing values generated)
544 |
545 | {com}. gen BALANCE = TOP2_5 / TOP1
546 | {txt}(170,440 missing values generated)
547 |
548 | {com}.
549 | . *- 保留有效样本
550 | . destring S0306a, replace
551 | {txt}S0306a: all characters numeric; {res}replaced {txt}as {res}byte
552 | {txt}
553 | {com}. drop if S0306a > 5
554 | {txt}(142,201 observations deleted)
555 |
556 | {com}. drop if TOP2_5 == .
557 | {txt}(28,239 observations deleted)
558 |
559 | {com}. duplicates drop STKCD YEAR, force
560 |
561 | {p 0 4}{txt}Duplicates in terms of {res} STKCD YEAR{p_end}
562 |
563 | {txt}(84,678 observations deleted)
564 |
565 | {com}.
566 | . *- 保留有效变量
567 | . keep STKCD YEAR BALANCE TOP1
568 | {txt}
569 | {com}.
570 | . *- 补充变量标签
571 | . label var YEAR "观测年份"
572 | {txt}
573 | {com}. label var TOP1 "第一大股东持股数量"
574 | {txt}
575 | {com}. label var BALANCE "股权制衡度"
576 | {txt}
577 | {com}.
578 | . *- 排序与保存数据
579 | . order STKCD YEAR BALANCE TOP1
580 | {txt}
581 | {com}. label data "股东股本相关数据-1 - From Shutter Zor"
582 | {txt}
583 | {com}. save "DataB-Hub/Data7-1.dta", replace
584 | {txt}(note: file DataB-Hub/Data7-1.dta not found)
585 | file DataB-Hub/Data7-1.dta saved
586 |
587 | {com}.
588 | . *- 股东股本相关数据 - 2
589 | . import excel using "DataA-Original/HLD_Shareholders1.xlsx", first clear
590 | {res}{text}(5 vars, 1,000,002 obs)
591 |
592 | {com}. labone, nrow(1 2) concat("_")
593 | {txt}
594 | {com}. drop in 1/2
595 | {txt}(2 observations deleted)
596 |
597 | {com}.
598 | . *- 仅保留年报数据
599 | . keep if substr(Reptdt,6,2) == "12"
600 | {txt}(716,292 observations deleted)
601 |
602 | {com}.
603 | . *- 重命名变量
604 | . rename Stkcd STKCD
605 | {res}{txt}
606 | {com}.
607 | . *- 生成变量 - 观测年份
608 | . gen YEAR = real(substr(Reptdt,1,4))
609 | {txt}
610 | {com}.
611 | . *- 生成变量 - 第一大股东持股数量 TOP1
612 | . destring S0304a, replace
613 | {txt}S0304a: all characters numeric; {res}replaced {txt}as {res}double
614 | {txt}
615 | {com}. bys STKCD YEAR: egen TOP1 = max(S0304a)
616 | {txt}
617 | {com}.
618 | . *- 生成变量 - 股权制衡度 BALANCE
619 | . bys STKCD YEAR: egen TOP2_5 = sum(S0304a) if S0306a=="2" | S0306a=="3" | S0306a=="4" | S0306a=="5" // 生成第二到第五大股东持股比例之和
620 | {txt}(171079 missing values generated)
621 |
622 | {com}. gen BALANCE = TOP2_5 / TOP1
623 | {txt}(171,079 missing values generated)
624 |
625 | {com}.
626 | . *- 保留有效样本
627 | . destring S0306a, replace
628 | {txt}S0306a: all characters numeric; {res}replaced {txt}as {res}byte
629 | {txt}
630 | {com}. drop if S0306a > 5
631 | {txt}(142,907 observations deleted)
632 |
633 | {com}. drop if TOP2_5 == .
634 | {txt}(28,172 observations deleted)
635 |
636 | {com}. duplicates drop STKCD YEAR, force
637 |
638 | {p 0 4}{txt}Duplicates in terms of {res} STKCD YEAR{p_end}
639 |
640 | {txt}(84,458 observations deleted)
641 |
642 | {com}.
643 | . *- 保留有效变量
644 | . keep STKCD YEAR BALANCE TOP1
645 | {txt}
646 | {com}.
647 | . *- 补充变量标签
648 | . label var YEAR "观测年份"
649 | {txt}
650 | {com}. label var TOP1 "第一大股东持股数量"
651 | {txt}
652 | {com}. label var BALANCE "股权制衡度"
653 | {txt}
654 | {com}.
655 | . *- 排序与保存数据
656 | . order STKCD YEAR BALANCE TOP1
657 | {txt}
658 | {com}. label data "股东股本相关数据-2 - From Shutter Zor"
659 | {txt}
660 | {com}. save "DataB-Hub/Data7-2.dta", replace
661 | {txt}(note: file DataB-Hub/Data7-2.dta not found)
662 | file DataB-Hub/Data7-2.dta saved
663 |
664 | {com}.
665 | . *- 股东股本相关数据 - 3
666 | . import excel using "DataA-Original/HLD_Shareholders2.xlsx", first clear
667 | {res}{text}(5 vars, 114,565 obs)
668 |
669 | {com}. labone, nrow(1 2) concat("_")
670 | {txt}
671 | {com}. drop in 1/2
672 | {txt}(2 observations deleted)
673 |
674 | {com}.
675 | . *- 仅保留年报数据
676 | . keep if substr(Reptdt,6,2) == "12"
677 | {txt}(87,657 observations deleted)
678 |
679 | {com}.
680 | . *- 重命名变量
681 | . rename Stkcd STKCD
682 | {res}{txt}
683 | {com}.
684 | . *- 生成变量 - 观测年份
685 | . gen YEAR = real(substr(Reptdt,1,4))
686 | {txt}
687 | {com}.
688 | . *- 生成变量 - 第一大股东持股数量 TOP1
689 | . destring S0304a, replace
690 | {txt}S0304a: all characters numeric; {res}replaced {txt}as {res}double
691 | {txt}
692 | {com}. bys STKCD YEAR: egen TOP1 = max(S0304a)
693 | {txt}
694 | {com}.
695 | . *- 生成变量 - 股权制衡度 BALANCE
696 | . bys STKCD YEAR: egen TOP2_5 = sum(S0304a) if S0306a=="2" | S0306a=="3" | S0306a=="4" | S0306a=="5" // 生成第二到第五大股东持股比例之和
697 | {txt}(16171 missing values generated)
698 |
699 | {com}. gen BALANCE = TOP2_5 / TOP1
700 | {txt}(16,171 missing values generated)
701 |
702 | {com}.
703 | . *- 保留有效样本
704 | . destring S0306a, replace
705 | {txt}S0306a: all characters numeric; {res}replaced {txt}as {res}byte
706 | {txt}
707 | {com}. drop if S0306a > 5
708 | {txt}(13,484 observations deleted)
709 |
710 | {com}. drop if TOP2_5 == .
711 | {txt}(2,687 observations deleted)
712 |
713 | {com}. duplicates drop STKCD YEAR, force
714 |
715 | {p 0 4}{txt}Duplicates in terms of {res} STKCD YEAR{p_end}
716 |
717 | {txt}(8,050 observations deleted)
718 |
719 | {com}.
720 | . *- 保留有效变量
721 | . keep STKCD YEAR BALANCE TOP1
722 | {txt}
723 | {com}.
724 | . *- 补充变量标签
725 | . label var YEAR "观测年份"
726 | {txt}
727 | {com}. label var TOP1 "第一大股东持股数量"
728 | {txt}
729 | {com}. label var BALANCE "股权制衡度"
730 | {txt}
731 | {com}.
732 | . *- 排序与保存数据
733 | . order STKCD YEAR BALANCE TOP1
734 | {txt}
735 | {com}. label data "股东股本相关数据-3 - From Shutter Zor"
736 | {txt}
737 | {com}. save "DataB-Hub/Data7-3.dta", replace
738 | {txt}file DataB-Hub/Data7-3.dta saved
739 |
740 | {com}.
741 | . *- 合并股东股本相关数据
742 | . use "DataB-Hub/Data7-1.dta", clear
743 | {txt}(股东股本相关数据-1 - From Shutter Zor)
744 |
745 | {com}. append using "DataB-Hub/Data7-2.dta"
746 | {txt}
747 | {com}. append using "DataB-Hub/Data7-3.dta"
748 | {txt}
749 | {com}. label data "股东股本相关数据 - From Shutter Zor"
750 | {txt}
751 | {com}. save "DataB-Hub/Data7.dta", replace
752 | {txt}file DataB-Hub/Data7.dta saved
753 |
754 | {com}. erase "DataB-Hub/Data7-1.dta"
755 | {txt}
756 | {com}. erase "DataB-Hub/Data7-2.dta"
757 | {txt}
758 | {com}.
759 | . *- 高管动态相关数据
760 | . /* 包含变量:BOARD INDBOARD MHOLD */
761 | .
762 | . *- 高管动态数据
763 | . import excel using "DataA-Original/CG_ManagerShareSalary.xlsx", first clear
764 | {res}{text}(6 vars, 122,980 obs)
765 |
766 | {com}. labone, nrow(1 2) concat("_")
767 | {txt}
768 | {com}. drop in 1/2
769 | {txt}(2 observations deleted)
770 |
771 | {com}.
772 | . *- 仅保留年末在职人员样本
773 | . keep if StatisticalCaliber == "1"
774 | {txt}(61,491 observations deleted)
775 |
776 | {com}.
777 | . *- 重命名变量
778 | . rename Symbol STKCD
779 | {res}{txt}
780 | {com}.
781 | . *- 生成变量 - 观测年份 YEAR
782 | . gen YEAR = real(substr(Enddate,1,4))
783 | {txt}
784 | {com}.
785 | . *- 生成变量 - 董事规模 BOARD
786 | . destring DirectorNumber, replace
787 | {txt}DirectorNumber: all characters numeric; {res}replaced {txt}as {res}byte
788 | {txt}
789 | {com}. gen BOARD = ln(DirectorNumber)
790 | {txt}(31 missing values generated)
791 |
792 | {com}.
793 | . *- 生成变量 - 独立董事占比 INDBOARD
794 | . destring IndependentDirectorNumber, replace
795 | {txt}IndependentDirectorNumber: all characters numeric; {res}replaced {txt}as {res}byte
796 | {txt}
797 | {com}. gen INDBOARD = IndependentDirectorNumber / DirectorNumber
798 | {txt}(31 missing values generated)
799 |
800 | {com}.
801 | . *- 管理层持股数量
802 | . destring Holdshares, replace
803 | {txt}Holdshares: all characters numeric; {res}replaced {txt}as {res}double
804 | {txt}(2028 missing values generated)
805 | {res}{txt}
806 | {com}.
807 | . *- 保留有效变量
808 | . keep STKCD YEAR BOARD INDBOARD Holdshares
809 | {txt}
810 | {com}.
811 | . *- 补充变量标签
812 | . label var YEAR "观测年份"
813 | {txt}
814 | {com}. label var BOARD "董事规模"
815 | {txt}
816 | {com}. label var INDBOARD "独立董事占比"
817 | {txt}
818 | {com}.
819 | . *- 保存数据
820 | . label data "高管动态相关数据-1 - From Shutter Zor"
821 | {txt}
822 | {com}. save "DataB-Hub/Data8-1.dta", replace
823 | {txt}(note: file DataB-Hub/Data8-1.dta not found)
824 | file DataB-Hub/Data8-1.dta saved
825 |
826 | {com}.
827 | . *- 股本结构文件
828 | . import excel using "DataA-Original/CG_Capchg.xlsx", first clear
829 | {res}{text}(3 vars, 61,494 obs)
830 |
831 | {com}. labone, nrow(1 2) concat("_")
832 | {txt}
833 | {com}. drop in 1/2
834 | {txt}(2 observations deleted)
835 |
836 | {com}.
837 | . *- 重命名变量
838 | . rename Stkcd STKCD
839 | {res}{txt}
840 | {com}.
841 | . *- 生成变量 - 观测年份 YEAR
842 | . gen YEAR = real(substr(Reptdt,1,4))
843 | {txt}
844 | {com}.
845 | . *- 补充变量标签
846 | . label var YEAR "观测年份"
847 | {txt}
848 | {com}.
849 | . *- 保留有效变量
850 | . keep STKCD YEAR Nshrttl
851 | {txt}
852 | {com}.
853 | . *- 保存数据
854 | . label data "高管动态相关数据-2 - From Shutter Zor"
855 | {txt}
856 | {com}. save "DataB-Hub/Data8-2.dta", replace
857 | {txt}(note: file DataB-Hub/Data8-2.dta not found)
858 | file DataB-Hub/Data8-2.dta saved
859 |
860 | {com}.
861 | . *- 合并高管动态与股本结构,主要是计算MHOLD
862 | . // 2024/12/31 开始,取消 “仅保留合并上的结果,即取消 keep if _merge == 3”
863 | . use "DataB-Hub/Data8-1.dta", clear
864 | {txt}(高管动态相关数据-1 - From Shutter Zor)
865 |
866 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data8-2.dta"
867 | {res}
868 | {txt}{col 5}Result{col 38}# of obs.
869 | {col 5}{hline 41}
870 | {col 5}not matched{col 30}{res} 5
871 | {txt}{col 9}from master{col 30}{res} 0{txt} (_merge==1)
872 | {col 9}from using{col 30}{res} 5{txt} (_merge==2)
873 |
874 | {col 5}matched{col 30}{res} 61,487{txt} (_merge==3)
875 | {col 5}{hline 41}
876 |
877 | {com}. drop _merge
878 | {txt}
879 | {com}.
880 | . *- 生成变量 - 管理层持股比例 MHOLD
881 | . destring Nshrttl, replace
882 | {txt}Nshrttl: all characters numeric; {res}replaced {txt}as {res}double
883 | {txt}
884 | {com}. gen MHOLD = Holdshares / Nshrttl
885 | {txt}(2,033 missing values generated)
886 |
887 | {com}.
888 | . *- 保留有效变量
889 | . keep STKCD YEAR BOARD INDBOARD MHOLD
890 | {txt}
891 | {com}.
892 | . *- 补充变量标签
893 | . label var MHOLD "管理层持股比例"
894 | {txt}
895 | {com}.
896 | . *- 排序与保存数据
897 | . order STKCD YEAR BOARD INDBOARD MHOLD
898 | {txt}
899 | {com}. label data "高管动态与股本结构相关数据 - From Shutter Zor"
900 | {txt}
901 | {com}. save "DataB-Hub/Data8.dta", replace
902 | {txt}file DataB-Hub/Data8.dta saved
903 |
904 | {com}. erase "DataB-Hub/Data8-1.dta"
905 | {txt}
906 | {com}. erase "DataB-Hub/Data8-2.dta"
907 | {txt}
908 | {com}.
909 | . *- 高管人数、持股相关数据
910 | . /* 包含变量:DUAL */
911 | . import excel using "DataA-Original/CG_Ybasic.xlsx", first clear
912 | {res}{text}(3 vars, 61,493 obs)
913 |
914 | {com}. labone, nrow(1 2) concat("_")
915 | {txt}
916 | {com}. drop in 1/2
917 | {txt}(2 observations deleted)
918 |
919 | {com}.
920 | . *- 重命名变量
921 | . rename Stkcd STKCD
922 | {res}{txt}
923 | {com}.
924 | . *- 生成变量 - 观测年份 YEAR
925 | . gen YEAR = real(substr(Reptdt,1,4))
926 | {txt}
927 | {com}.
928 | . *- 生成变量 - 两职合一 DUAL
929 | . destring Y1001b, replace
930 | {txt}Y1001b: all characters numeric; {res}replaced {txt}as {res}byte
931 | {txt}(1714 missing values generated)
932 | {res}{txt}
933 | {com}. rename Y1001b DUAL
934 | {res}{txt}
935 | {com}. replace DUAL = 0 if DUAL == 2
936 | {txt}(43,579 real changes made)
937 |
938 | {com}.
939 | . *- 保留有效变量
940 | . keep STKCD YEAR DUAL
941 | {txt}
942 | {com}.
943 | . *- 补充变量标签
944 | . label var YEAR "观测年份"
945 | {txt}
946 | {com}. label var DUAL "两职合一"
947 | {txt}
948 | {com}.
949 | . *- 保存数据
950 | . label data "高管人数、持股相关数据 - From Shutter Zor"
951 | {txt}
952 | {com}. save "DataB-Hub/Data9.dta", replace
953 | {txt}file DataB-Hub/Data9.dta saved
954 |
955 | {com}.
956 | . *- 合并治理结构相关数据
957 | . // 2024/12/31 开始,取消 “仅保留合并上的结果,即取消 keep if _merge == 3”
958 | . use "DataB-Hub/Data7.dta", clear
959 | {txt}(股东股本相关数据 - From Shutter Zor)
960 |
961 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data8.dta"
962 | {res}
963 | {txt}{col 5}Result{col 38}# of obs.
964 | {col 5}{hline 41}
965 | {col 5}not matched{col 30}{res} 2,404
966 | {txt}{col 9}from master{col 30}{res} 3{txt} (_merge==1)
967 | {col 9}from using{col 30}{res} 2,401{txt} (_merge==2)
968 |
969 | {col 5}matched{col 30}{res} 59,091{txt} (_merge==3)
970 | {col 5}{hline 41}
971 |
972 | {com}. drop _merge
973 | {txt}
974 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data9.dta"
975 | {res}
976 | {txt}{col 5}Result{col 38}# of obs.
977 | {col 5}{hline 41}
978 | {col 5}not matched{col 30}{res} 4
979 | {txt}{col 9}from master{col 30}{res} 4{txt} (_merge==1)
980 | {col 9}from using{col 30}{res} 0{txt} (_merge==2)
981 |
982 | {col 5}matched{col 30}{res} 61,491{txt} (_merge==3)
983 | {col 5}{hline 41}
984 |
985 | {com}. drop _merge
986 | {txt}
987 | {com}.
988 | . *- 排序与保存数据
989 | . order STKCD YEAR BALANCE BOARD INDBOARD MHOLD TOP1 DUAL
990 | {txt}
991 | {com}. label data "治理结构相关变量6个 - From Shutter Zor"
992 | {txt}
993 | {com}. save "DataB-Hub/Data10.dta", replace
994 | {txt}file DataB-Hub/Data10.dta saved
995 |
996 | {com}.
997 | . /* 本部分生成的 Data10 用于后续合并 */
998 | . /* BALANCE BOARD INDBOARD MHOLD TOP1 DUAL */
999 | .
1000 | . // 结束时间记录:
1001 | . dis "`c(current_date)' `c(current_time)'"
1002 | {res}31 Dec 2024 12:12:32
1003 | {txt}
1004 | {com}. ********************************************************************************
1005 | .
1006 | .
1007 | .
1008 | . ********************************************************************************
1009 | . // 开始时间记录:
1010 | . dis "`c(current_date)' `c(current_time)'"
1011 | {res}31 Dec 2024 12:12:32
1012 | {txt}
1013 | {com}.
1014 | . *- 清洗财务指标分析相关数据
1015 | . /* 包含变量:BM TobinQ */
1016 | .
1017 | . import excel using "DataA-Original/FI_T10.xlsx", first clear
1018 | {res}{text}(9 vars, 228,927 obs)
1019 |
1020 | {com}. labone, nrow(1 2) concat("_")
1021 | {txt}
1022 | {com}. drop in 1/2
1023 | {txt}(2 observations deleted)
1024 |
1025 | {com}.
1026 | . *- 仅保留年报数据
1027 | . keep if substr(Accper,6,2) == "12"
1028 | {txt}(169,237 observations deleted)
1029 |
1030 | {com}.
1031 | . *- 重命名变量
1032 | . rename (Stkcd ShortName F100901A F100902A F100903A F100904A F101001A F101002A) (STKCD STKNM TobinQ1 TobinQ2 TobinQ3 TobinQ4 BM1 BM2)
1033 | {res}{txt}
1034 | {com}.
1035 | . *- 生成变量 - 观测年份 YEAR
1036 | . gen YEAR = real(substr(Accper,1,4))
1037 | {txt}
1038 | {com}.
1039 | . *- 生成变量 - 账面市值比 BM 与 托宾Q值 TobinQ
1040 | . destring BM* TobinQ*, replace
1041 | {txt}BM1: all characters numeric; {res}replaced {txt}as {res}double
1042 | {txt}BM2: all characters numeric; {res}replaced {txt}as {res}double
1043 | {txt}TobinQ1: all characters numeric; {res}replaced {txt}as {res}double
1044 | {txt}TobinQ2: all characters numeric; {res}replaced {txt}as {res}double
1045 | {txt}TobinQ3: all characters numeric; {res}replaced {txt}as {res}double
1046 | {txt}TobinQ4: all characters numeric; {res}replaced {txt}as {res}double
1047 | {txt}
1048 | {com}.
1049 | . *- 保留有效变量
1050 | . keep STKCD YEAR BM* TobinQ*
1051 | {txt}
1052 | {com}.
1053 | . *- 补充变量标签
1054 | . label var YEAR "观测年份"
1055 | {txt}
1056 | {com}.
1057 | . *- 保存数据
1058 | . label data "财务指标分析相关变量2个"
1059 | {txt}
1060 | {com}. save "DataB-Hub/Data11.dta", replace
1061 | {txt}file DataB-Hub/Data11.dta saved
1062 |
1063 | {com}.
1064 | . /* 本部分生成的 Data11 用于后续合并 */
1065 | . /* BM TobinQ */
1066 | .
1067 | . // 结束时间记录:
1068 | . dis "`c(current_date)' `c(current_time)'"
1069 | {res}31 Dec 2024 12:12:48
1070 | {txt}
1071 | {com}. ********************************************************************************
1072 | .
1073 | .
1074 | .
1075 | . ********************************************************************************
1076 | . // 开始时间记录:
1077 | . dis "`c(current_date)' `c(current_time)'"
1078 | {res}31 Dec 2024 12:12:48
1079 | {txt}
1080 | {com}.
1081 | . *- 清洗机构投资者相关数据
1082 | . /* 包含变量:INSTITUTION */
1083 | .
1084 | . import excel using "DataA-Original/INI_HolderSystematics.xlsx", first clear
1085 | {res}{text}(4 vars, 226,092 obs)
1086 |
1087 | {com}. labone, nrow(1 2) concat("_")
1088 | {txt}
1089 | {com}. drop in 1/2
1090 | {txt}(2 observations deleted)
1091 |
1092 | {com}.
1093 | . *- 仅保留年报数据
1094 | . keep if substr(EndDate,6,2) == "12"
1095 | {txt}(165,609 observations deleted)
1096 |
1097 | {com}.
1098 | . *- 重命名变量
1099 | . rename (Symbol InsInvestorProp InsInvestorProp1) (STKCD INSTITUTION1 INSTITUTION2)
1100 | {res}{txt}
1101 | {com}.
1102 | . *- 生成变量 - 观测年份 YEAR
1103 | . gen YEAR = real(substr(EndDate,1,4))
1104 | {txt}
1105 | {com}.
1106 | . *- 生成变量 - 机构投资者比例 INSTITUTION
1107 | . destring INSTITUTION*, replace
1108 | {txt}INSTITUTION1: all characters numeric; {res}replaced {txt}as {res}double
1109 | {txt}INSTITUTION2: all characters numeric; {res}replaced {txt}as {res}double
1110 | {txt}(411 missing values generated)
1111 | {res}{txt}
1112 | {com}.
1113 | . *- 保留有效变量
1114 | . keep STKCD YEAR INSTITUTION*
1115 | {txt}
1116 | {com}.
1117 | . *- 补充变量标签
1118 | . label var YEAR "观测年份"
1119 | {txt}
1120 | {com}.
1121 | . *- 保存数据
1122 | . label data "机构投资者相关变量1个"
1123 | {txt}
1124 | {com}. save "DataB-Hub/Data12.dta", replace
1125 | {txt}file DataB-Hub/Data12.dta saved
1126 |
1127 | {com}.
1128 | . /* 本部分生成的 Data12 用于后续合并 */
1129 | . /* INSTITUTION */
1130 | .
1131 | . // 结束时间记录:
1132 | . dis "`c(current_date)' `c(current_time)'"
1133 | {res}31 Dec 2024 12:12:55
1134 | {txt}
1135 | {com}. ********************************************************************************
1136 | .
1137 | .
1138 | .
1139 | . ********************************************************************************
1140 | . // 开始时间记录:
1141 | . dis "`c(current_date)' `c(current_time)'"
1142 | {res}31 Dec 2024 12:12:55
1143 | {txt}
1144 | {com}.
1145 | . *- 清洗分析师预测相关数据
1146 | . /* 包含变量:AUDIT */
1147 | .
1148 | . import excel using "DataA-Original/AF_CFEATUREPROFILE.xlsx", first clear
1149 | {res}{text}(4 vars, 61,048 obs)
1150 |
1151 | {com}. labone, nrow(1 2) concat("_")
1152 | {txt}
1153 | {com}. drop in 1/2
1154 | {txt}(2 observations deleted)
1155 |
1156 | {com}.
1157 | . *- 仅保留年报数据
1158 | . keep if substr(Accper,6,2) == "12"
1159 | {txt}(0 observations deleted)
1160 |
1161 | {com}.
1162 | . *- 重命名变量
1163 | . rename (Stknmec Stkcd) (STKNM STKCD)
1164 | {res}{txt}
1165 | {com}.
1166 | . *- 生成变量 - 观测年份 YEAR
1167 | . gen YEAR = real(substr(Accper,1,4))
1168 | {txt}
1169 | {com}.
1170 | . *- 生成变量 - 是否由四大会计师事务所审计 AUDIT
1171 | . gen AUDIT = 1 if Big4 == "Y"
1172 | {txt}(56,865 missing values generated)
1173 |
1174 | {com}. replace AUDIT = 0 if Big4 == "N"
1175 | {txt}(56,510 real changes made)
1176 |
1177 | {com}.
1178 | . *- 保留有效变量
1179 | . keep STKCD YEAR AUDIT
1180 | {txt}
1181 | {com}.
1182 | . *- 补充变量标签
1183 | . label var YEAR "观测年份"
1184 | {txt}
1185 | {com}. label var AUDIT "是否由四大会计师事务所审计"
1186 | {txt}
1187 | {com}.
1188 | . *- 保存数据
1189 | . duplicates drop STKCD YEAR, force
1190 |
1191 | {p 0 4}{txt}Duplicates in terms of {res} STKCD YEAR{p_end}
1192 |
1193 | {txt}(1 observation deleted)
1194 |
1195 | {com}. label data "分析师预测相关变量1个"
1196 | {txt}
1197 | {com}. save "DataB-Hub/Data13.dta", replace
1198 | {txt}file DataB-Hub/Data13.dta saved
1199 |
1200 | {com}.
1201 | . /* 本部分生成的 Data13 用于后续合并 */
1202 | . /* AUDIT */
1203 | .
1204 | . // 结束时间记录:
1205 | . dis "`c(current_date)' `c(current_time)'"
1206 | {res}31 Dec 2024 12:12:57
1207 | {txt}
1208 | {com}. ********************************************************************************
1209 | .
1210 | .
1211 | .
1212 | . ********************************************************************************
1213 | . // 开始时间记录:
1214 | . dis "`c(current_date)' `c(current_time)'"
1215 | {res}31 Dec 2024 12:12:57
1216 | {txt}
1217 | {com}.
1218 | . *- 清洗财务报告审计意见相关数据
1219 | . /* 包含变量:OPINION */
1220 | .
1221 | . import excel using "DataA-Original/FIN_Audit.xlsx", first clear
1222 | {res}{text}(4 vars, 63,201 obs)
1223 |
1224 | {com}. labone, nrow(1 2) concat("_")
1225 | {txt}
1226 | {com}. drop in 1/2
1227 | {txt}(2 observations deleted)
1228 |
1229 | {com}.
1230 | . *- 仅保留年报数据
1231 | . keep if substr(Accper,6,2) == "12"
1232 | {txt}(1,700 observations deleted)
1233 |
1234 | {com}.
1235 | . *- 重命名变量
1236 | . rename (Stkcd Stknme) (STKCD STKNM)
1237 | {res}{txt}
1238 | {com}.
1239 | . *- 生成变量 - 观测年份 YEAR
1240 | . gen YEAR = real(substr(Accper,1,4))
1241 | {txt}
1242 | {com}.
1243 | . *- 生成变量 - 是否由四大会计师事务所审计 AUDIT
1244 | . gen OPINION = 1 if Audittyp == "标准无保留意见"
1245 | {txt}(3,552 missing values generated)
1246 |
1247 | {com}. replace OPINION = 0 if Audittyp != "标准无保留意见"
1248 | {txt}(3,552 real changes made)
1249 |
1250 | {com}.
1251 | . *- 保留有效变量
1252 | . keep STKCD YEAR OPINION
1253 | {txt}
1254 | {com}.
1255 | . *- 补充变量标签
1256 | . label var YEAR "观测年份"
1257 | {txt}
1258 | {com}. label var OPINION "是否标准无保留意见"
1259 | {txt}
1260 | {com}.
1261 | . *- 保存数据
1262 | . label data "财务报告审计意见相关变量1个"
1263 | {txt}
1264 | {com}. save "DataB-Hub/Data14.dta", replace
1265 | {txt}file DataB-Hub/Data14.dta saved
1266 |
1267 | {com}.
1268 | . /* 本部分生成的 Data14 用于后续合并 */
1269 | . /* OPINION */
1270 | .
1271 | . // 结束时间记录:
1272 | . dis "`c(current_date)' `c(current_time)'"
1273 | {res}31 Dec 2024 12:13:00
1274 | {txt}
1275 | {com}. ********************************************************************************
1276 | .
1277 | .
1278 | .
1279 | . ********************************************************************************
1280 | . // 开始时间记录:
1281 | . dis "`c(current_date)' `c(current_time)'"
1282 | {res}31 Dec 2024 12:13:00
1283 | {txt}
1284 | {com}.
1285 | . *- 清洗股权性质相关数据
1286 | . /* 包含变量:SOE */
1287 | .
1288 | . import excel using "DataA-Original/EN_EquityNatureAll.xlsx", first clear
1289 | {res}{text}(4 vars, 59,098 obs)
1290 |
1291 | {com}. labone, nrow(1 2) concat("_")
1292 | {txt}
1293 | {com}. drop in 1/2
1294 | {txt}(2 observations deleted)
1295 |
1296 | {com}.
1297 | . *- 仅保留年报数据
1298 | . keep if substr(EndDate,6,2) == "12"
1299 | {txt}(0 observations deleted)
1300 |
1301 | {com}.
1302 | . *- 重命名变量
1303 | . rename (Symbol ShortName) (STKCD STKNM)
1304 | {res}{txt}
1305 | {com}.
1306 | . *- 生成变量 - 观测年份 YEAR
1307 | . gen YEAR = real(substr(EndDate,1,4))
1308 | {txt}
1309 | {com}.
1310 | . *- 生成变量 - 是否为国企 SOE
1311 | . gen SOE = 1 if EquityNature == "国企"
1312 | {txt}(36,522 missing values generated)
1313 |
1314 | {com}. replace SOE = 0 if EquityNature != "国企"
1315 | {txt}(36,522 real changes made)
1316 |
1317 | {com}.
1318 | . *- 保留有效变量
1319 | . keep STKCD YEAR SOE
1320 | {txt}
1321 | {com}.
1322 | . *- 补充变量标签
1323 | . label var YEAR "观测年份"
1324 | {txt}
1325 | {com}. label var SOE "是否为国企"
1326 | {txt}
1327 | {com}.
1328 | . *- 保存数据
1329 | . label data "股权性质相关变量1个"
1330 | {txt}
1331 | {com}. save "DataB-Hub/Data15.dta", replace
1332 | {txt}file DataB-Hub/Data15.dta saved
1333 |
1334 | {com}.
1335 | . /* 本部分生成的 Data15 用于后续合并 */
1336 | . /* SOE */
1337 | .
1338 | . // 结束时间记录:
1339 | . dis "`c(current_date)' `c(current_time)'"
1340 | {res}31 Dec 2024 12:13:02
1341 | {txt}
1342 | {com}. ********************************************************************************
1343 | .
1344 | .
1345 | .
1346 | .
1347 | .
1348 | . ********************************************************************************
1349 | . // 开始时间记录:
1350 | . dis "`c(current_date)' `c(current_time)'"
1351 | {res}31 Dec 2024 12:13:02
1352 | {txt}
1353 | {com}.
1354 | . /* 至此完成了所有数据变量的计算,接下来需要将所有内容完全合并 */
1355 | . /* 文件位置:DataB-Hub
1356 | > Data1.dta: STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE
1357 | > Data6.dta: CFO GROWTH LEV MFEE OCCUPY ROA ROE SIZE TAT
1358 | > Data10.dta: BALANCE BOARD INDBOARD MHOLD TOP1 DUAL
1359 | > Data11.dta: BM TobinQ
1360 | > Data12.dta: INSTITUTION
1361 | > Data13.dta: AUDIT
1362 | > Data14.dta: OPINION
1363 | > Data15.dta: SOE
1364 | > 总计: 33 种变量,其中 AGE、BM、CFO、TobinQ 含有多类
1365 | > */
1366 | .
1367 | . *- 最终合并
1368 | . // 2024/12/31 开始,取消 “仅保留合并上的结果,即取消 keep if _merge == 3”
1369 | . use "DataB-Hub/Data1.dta", clear
1370 | {txt}(基本信息相关变量11+年龄 - From Shutter Zor)
1371 |
1372 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data6.dta"
1373 | {res}{txt}{p 0 7 2}
1374 | (note: variable
1375 | YEAR was
1376 | int, now float to accommodate using data's values)
1377 | {p_end}
1378 |
1379 | {col 5}Result{col 38}# of obs.
1380 | {col 5}{hline 41}
1381 | {col 5}not matched{col 30}{res} 4,376
1382 | {txt}{col 9}from master{col 30}{res} 7{txt} (_merge==1)
1383 | {col 9}from using{col 30}{res} 4,369{txt} (_merge==2)
1384 |
1385 | {col 5}matched{col 30}{res} 60,752{txt} (_merge==3)
1386 | {col 5}{hline 41}
1387 |
1388 | {com}. drop _merge
1389 | {txt}
1390 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data10.dta"
1391 | {res}
1392 | {txt}{col 5}Result{col 38}# of obs.
1393 | {col 5}{hline 41}
1394 | {col 5}not matched{col 30}{res} 3,633
1395 | {txt}{col 9}from master{col 30}{res} 3,633{txt} (_merge==1)
1396 | {col 9}from using{col 30}{res} 0{txt} (_merge==2)
1397 |
1398 | {col 5}matched{col 30}{res} 61,495{txt} (_merge==3)
1399 | {col 5}{hline 41}
1400 |
1401 | {com}. drop _merge
1402 | {txt}
1403 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data11.dta"
1404 | {res}
1405 | {txt}{col 5}Result{col 38}# of obs.
1406 | {col 5}{hline 41}
1407 | {col 5}not matched{col 30}{res} 5,440
1408 | {txt}{col 9}from master{col 30}{res} 5,440{txt} (_merge==1)
1409 | {col 9}from using{col 30}{res} 0{txt} (_merge==2)
1410 |
1411 | {col 5}matched{col 30}{res} 59,688{txt} (_merge==3)
1412 | {col 5}{hline 41}
1413 |
1414 | {com}. drop _merge
1415 | {txt}
1416 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data12.dta"
1417 | {res}
1418 | {txt}{col 5}Result{col 38}# of obs.
1419 | {col 5}{hline 41}
1420 | {col 5}not matched{col 30}{res} 4,693
1421 | {txt}{col 9}from master{col 30}{res} 4,670{txt} (_merge==1)
1422 | {col 9}from using{col 30}{res} 23{txt} (_merge==2)
1423 |
1424 | {col 5}matched{col 30}{res} 60,458{txt} (_merge==3)
1425 | {col 5}{hline 41}
1426 |
1427 | {com}. drop _merge
1428 | {txt}
1429 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data13.dta"
1430 | {res}
1431 | {txt}{col 5}Result{col 38}# of obs.
1432 | {col 5}{hline 41}
1433 | {col 5}not matched{col 30}{res} 4,674
1434 | {txt}{col 9}from master{col 30}{res} 4,390{txt} (_merge==1)
1435 | {col 9}from using{col 30}{res} 284{txt} (_merge==2)
1436 |
1437 | {col 5}matched{col 30}{res} 60,761{txt} (_merge==3)
1438 | {col 5}{hline 41}
1439 |
1440 | {com}. drop _merge
1441 | {txt}
1442 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data14.dta"
1443 | {res}
1444 | {txt}{col 5}Result{col 38}# of obs.
1445 | {col 5}{hline 41}
1446 | {col 5}not matched{col 30}{res} 3,936
1447 | {txt}{col 9}from master{col 30}{res} 3,936{txt} (_merge==1)
1448 | {col 9}from using{col 30}{res} 0{txt} (_merge==2)
1449 |
1450 | {col 5}matched{col 30}{res} 61,499{txt} (_merge==3)
1451 | {col 5}{hline 41}
1452 |
1453 | {com}. drop _merge
1454 | {txt}
1455 | {com}. merge 1:1 STKCD YEAR using "DataB-Hub/Data15.dta"
1456 | {res}
1457 | {txt}{col 5}Result{col 38}# of obs.
1458 | {col 5}{hline 41}
1459 | {col 5}not matched{col 30}{res} 6,339
1460 | {txt}{col 9}from master{col 30}{res} 6,339{txt} (_merge==1)
1461 | {col 9}from using{col 30}{res} 0{txt} (_merge==2)
1462 |
1463 | {col 5}matched{col 30}{res} 59,096{txt} (_merge==3)
1464 | {col 5}{hline 41}
1465 |
1466 | {com}. drop _merge
1467 | {txt}
1468 | {com}.
1469 | . *- 排序与保存数据
1470 | . order STKCD STKNM YEAR INDCD INDNM PROVCD PROVNM CITYCD CITYNM MARKET STATE AGE1 AGE2 BALANCE BM1 BM2 BOARD CFO1 CFO2 GROWTH INDBOARD INSTITUTION1 INSTITUTION2 LEV MFEE MHOLD OCCUPY ROA ROE SIZE TAT TobinQ1 TobinQ2 TobinQ3 TobinQ4 TOP1 AUDIT DUAL OPINION SOE
1471 | {txt}
1472 | {com}.
1473 | . label data "Commonly used control variables (2001-2023) by Shutter Zor (Shutter_Z@outlook)."
1474 | {txt}
1475 | {com}. save ControlVarsDetail.dta, replace
1476 | {txt}file ControlVarsDetail.dta saved
1477 |
1478 | {com}.
1479 | . // 结束时间记录:
1480 | . dis "`c(current_date)' `c(current_time)'"
1481 | {res}31 Dec 2024 12:13:02
1482 | {txt}
1483 | {com}. ********************************************************************************
1484 | . log close _all
1485 | {txt}name: {res}ShutterZorADXMU20241231
1486 | {txt}log: {res}F:\Doctor\GitHub Repos\Commonly-Used-Control-Variables\CSMAR CtrlVars Cleaning Log.smcl
1487 | {txt}log type: {res}smcl
1488 | {txt}closed on: {res}31 Dec 2024, 12:13:02
1489 | {txt}{.-}
1490 | {smcl}
1491 | {txt}{sf}{ul off}
--------------------------------------------------------------------------------
/ControlVarsDetail.dta:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ShutterZor/Commonly-Used-Control-Variables/d838158b47a09dc38af7891c83e705e833e1d856/ControlVarsDetail.dta
--------------------------------------------------------------------------------
/Image/Figure2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ShutterZor/Commonly-Used-Control-Variables/d838158b47a09dc38af7891c83e705e833e1d856/Image/Figure2.png
--------------------------------------------------------------------------------
/Image/tmp.txt:
--------------------------------------------------------------------------------
1 | keeping file
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CSMAR-上市公司实证常用控制变量
2 |
3 | ## 1. 样本概况
4 |
5 | **上市公司:**
6 |
7 | - 全部A股
8 | - 上证A股、深证A股、北证A股、上证主板A股、深圳主板A股、科创板、创业板
9 | - 全部B股:
10 | - 上证B股、深证B股
11 |
12 | **时间范围:**
13 |
14 | 2001 - 2023(含2001与2023)
15 |
16 | **包含变量:**
17 |
18 | - 11个基本信息变量
19 | - 22个常用控制变量,其中连续变量18个,虚拟变量4个
20 |
21 | ## 2. 常用控制变量明细(ControlVarsDetail.dta)2001-2023
22 |
23 | | 变量 | 定义 | 备注 |
24 | | ------------ | :---------------------------------------------------------- | :----------------------------------------------------------- |
25 | | **基本信息** | | |
26 | | STKCD | 证券代码 | |
27 | | STKNM | 证券简称 | |
28 | | YEAR | 观测年份 | |
29 | | INDCD | 行业代码 | 证监会2012行业分类标准 |
30 | | INDNM | 行业名称 | 证监会2012行业分类标准 |
31 | | PROVCD | 省份代码 | |
32 | | PROVNM | 省份名称 | |
33 | | CITYCD | 城市代码 | |
34 | | CITYNM | 城市名称 | |
35 | | MARKET | 股票市场板块 | 依据股票代码划分,详情见[划分释义](#释义) |
36 | | STATE | 上市状态 | |
37 | | **连续变量** | | |
38 | | AGE | [企业年龄](#企业年龄),企业从成立或上市到观测年份的年数 | 公司研究系列👉上市公司基本信息👉上市公司基本信息年度表 |
39 | | BALANCE | 股权制衡度,第二到第五大股东持股比例之和/第一大股东持股比例 | *公司研究系列👉股东👉股东信息👉十大股东文件* (注:本指标起始年份为2003年6月30日) |
40 | | BM | [账面市值比](#账面市值比),账面价值/[市场价值](#市场价值) | 公司研究系列👉财务指标分析👉相对价值指标 |
41 | | BOARD | 董事规模,董事会人数的自然对数 | 公司研究系列👉治理结构👉高管动态👉高管人数、持股及薪酬情况表 |
42 | | CFO | 现金流状况,经营活动产生的现金流量净额/总资产 | 公司研究系列👉财务报表👉现金流量表&资产负债表 |
43 | | GROWTH | 营业收入增长率,营业收入的年度增长率 | 公司研究系列👉财务报表👉利润表 |
44 | | INDBOARD | 独立董事占比,独董人数/董事会人数 | 公司研究系列👉治理结构👉高管动态👉高管人数、持股及薪酬情况表 |
45 | | INSTITUTION | 机构持股比例,机构投资者持有股份/总股数 | 公司研究系列👉机构投资者👉机构持股分类统计表 |
46 | | LEV | 资产负债率,总负债/总资产 | 公司研究系列👉财务报表👉资产负债表 |
47 | | MFEE | 管理层费用率,管理费用/营业收入 | 公司研究系列👉财务报表👉利润表 |
48 | | MHOLD | 管理层持股比例,董事、监事以及高管持股总数/总股数 | 公司研究系列👉治理结构👉高管动态 (高管人数、持股及薪酬情况表) &股东股本 (股本结构文件) |
49 | | OCCUPY | 大股东资金占用,其他应收款/总资产 | 公司研究系列👉财务报表👉资产负债表 |
50 | | ROA | 总资产收益率,净利润/总资产 | 公司研究系列👉财务报表👉利润表&资产负债表 |
51 | | ROE | 净资产收益率,净利润/净资产(所有者权益) | 公司研究系列👉财务报表👉利润表&资产负债表 |
52 | | SIZE | 公司规模,总资产的自然对数 | 公司研究系列👉财务报表👉资产负债表 |
53 | | TAT | 总资产周转率,营业收入/总资产 | 公司研究系列👉财务报表👉利润表&资产负债表 |
54 | | TobinQ | 托宾Q值,[企业的托宾Q值](#托宾Q值) | 公司研究系列👉财务指标分析👉相对价值指标 |
55 | | TOP1 | 第一大股东持股比例,第一大股东持股数量/总股数 | 公司研究系列👉治理结构👉股东股本👉十大股东文件 |
56 | | **虚拟变量** | | |
57 | | AUDIT | 是否由四大会计师事务所审计,是则取1,否则取0 | 公司研究系列👉分析师预测👉上司公司基本情况👉上市公司基本信息特色指标表 |
58 | | DUAL | 董事长与总经理是否为同一人,是则取1,否则取0 | 公司研究系列👉治理结构👉基本数据👉治理综合信息文件 |
59 | | OPINION | 审计意见是否为标准无保留意见,是则取1,否则取0 | 公司研究系列👉财务报告审计意见👉基本数据👉审计意见表文件 |
60 | | SOE | 企业股东性质是否为国有企业,是则取1,否则取0 | 公司研究系列👉股权性质👉中国上市公司股权性质文件 (注:本指标起始年份为2003年12月31日) |
61 |
62 | ### 释义
63 |
64 | **A股:** 人民币普通股票,在中国大陆注册、在中国大陆上市的普通股票,以人民币认购和交易。A股与具体的股票代码的对应关系如下:
65 |
66 | - 00开头,深证主板A股;30开头,深证创业板
67 | - 60开头,上证主板A股;68开头,上证科创版
68 | - 43、83、87开头,北证A股
69 |
70 | **B股:**
71 |
72 | - 20开头,深证B股
73 | - 90开头,上证B股
74 |
75 | ### 企业年龄
76 |
77 | 1. AGE1 = 企业从成立年份到观测年份的年龄
78 | 2. AGE2 = 企业从上市年份到观测年份的年龄
79 |
80 | ### 市场价值
81 |
82 | 1. 市值A = A股\*今收盘价A股当期值 + 境内上市的外资股B股\*今收盘价B股当期值(沪市\*CNY_USD, 深市/HKD_CNY, 转化为人民币) + (总股数-人民币普通股-境内上市的外资股B股) \* (所有者权益合计期末值/实收资本本期期末值) + 负债合计本期期末值
83 | 2. 市值B = (总股本-境内上市的外资股B股) \* 今收盘价A股当期值 + 境内上市的外资股B股 \* 今收盘价B股当期值(沪市\*CNY_USD, 深市/HKD_CNY, 转化为人民币) + 负债合计本期期末值
84 |
85 | ### 账面市值比
86 |
87 | 1. 账面市值比A = 资产总计 / 市值A
88 | 2. 账面市值比A = 资产总计 / 市值B
89 |
90 | ### 托宾Q值
91 |
92 | 1. 托宾Q值A = 市值A / 资产总计
93 | 2. 托宾Q值B = 市值A / (资产总计-无形资产净额-商誉净额)
94 | 3. 托宾Q值C = 市值B / 资产总计
95 | 4. 托宾Q值D = 市值B / (资产总计-无形资产净额-商誉净额)
96 |
97 | ## 3. 常用控制变量明细(ControlVarsDetail.dta)2024版
98 |
99 | | 变量 | 定义 | 备注 |
100 | | ------------ | :---------------------------------------------------------- | :----------------------------------------------------------- |
101 | | **基本信息** | | |
102 | | STKCD | 证券代码 | |
103 | | STKNM | 证券简称 | |
104 | | YEAR | 观测年份 | |
105 | | INDCD | 行业代码 | 证监会2012行业分类标准 |
106 | | INDNM | 行业名称 | 证监会2012行业分类标准 |
107 | | PROVCD | 省份代码 | |
108 | | PROVNM | 省份名称 | |
109 | | CITYCD | 城市代码 | |
110 | | CITYNM | 城市名称 | |
111 | | MARKET | 股票市场板块 | 依据股票代码划分,详情见[划分释义](#释义) |
112 | | STATE | 上市状态 | |
113 | | **连续变量** | | |
114 | | AGE | [企业年龄](#企业年龄),企业从成立或上市到观测年份的年数 | 公司研究系列👉上市公司基本信息👉上市公司基本信息年度表 |
115 | | BALANCE | 股权制衡度,第二到第五大股东持股比例之和/第一大股东持股比例 | 公司研究系列👉治理结构👉股东股本👉十大股东文件 |
116 | | BM | [账面市值比](#账面市值比),账面价值/[市场价值](#市场价值) | 公司研究系列👉财务指标分析👉相对价值指标 |
117 | | BOARD | 董事规模,董事会人数的自然对数 | 公司研究系列👉治理结构👉高管动态👉高管人数、持股及薪酬情况表 |
118 | | CFO | 现金流状况,经营活动产生的现金流量净额/总资产 | 公司研究系列👉财务报表👉现金流量表&资产负债表 |
119 | | GROWTH | 营业收入增长率,营业收入的年度增长率 | 公司研究系列👉财务报表👉利润表 |
120 | | INDBOARD | 独立董事占比,独董人数/董事会人数 | 公司研究系列👉治理结构👉高管动态👉高管人数、持股及薪酬情况表 |
121 | | INSTITUTION | 机构持股比例,机构投资者持有股份/总股数 | 公司研究系列👉机构投资者👉机构持股分类统计表 |
122 | | LEV | 资产负债率,总负债/总资产 | 公司研究系列👉财务报表👉资产负债表 |
123 | | MFEE | 管理层费用率,管理费用/营业收入 | 公司研究系列👉财务报表👉利润表 |
124 | | MHOLD | 管理层持股比例,董事、监事以及高管持股总数/总股数 | 公司研究系列👉治理结构👉高管动态 (高管人数、持股及薪酬情况表) &股东股本 (股本结构文件) |
125 | | OCCUPY | 大股东资金占用,其他应收款/总资产 | 公司研究系列👉财务报表👉资产负债表 |
126 | | ROA | 总资产收益率,净利润/总资产 | 公司研究系列👉财务报表👉利润表&资产负债表 |
127 | | ROE | 净资产收益率,净利润/净资产(所有者权益) | 公司研究系列👉财务报表👉利润表&资产负债表 |
128 | | SIZE | 公司规模,总资产的自然对数 | 公司研究系列👉财务报表👉资产负债表 |
129 | | TAT | 总资产周转率,营业收入/总资产 | 公司研究系列👉财务报表👉利润表&资产负债表 |
130 | | TobinQ | 托宾Q值,[企业的托宾Q值](#托宾Q值) | 公司研究系列👉财务指标分析👉相对价值指标 |
131 | | TOP1 | 第一大股东持股比例,第一大股东持股数量/总股数 | 公司研究系列👉治理结构👉股东股本👉十大股东文件 |
132 | | **虚拟变量** | | |
133 | | AUDIT | 是否由四大会计师事务所审计,是则取1,否则取0 | 公司研究系列👉分析师预测👉上司公司基本情况👉上市公司基本信息特色指标表 |
134 | | DUAL | 董事长与总经理是否为同一人,是则取1,否则取0 | 公司研究系列👉治理结构👉基本数据👉治理综合信息文件 |
135 | | OPINION | 审计意见是否为标准无保留意见,是则取1,否则取0 | 公司研究系列👉财务报告审计意见👉基本数据👉审计意见表文件 |
136 | | SOE | 企业股东性质是否为国有企业,是则取1,否则取0 | 公司研究系列👉股权性质👉中国上市公司股权性质文件 |
137 |
138 | ### 释义
139 |
140 | **A股:** 人民币普通股票,在中国大陆注册、在中国大陆上市的普通股票,以人民币认购和交易。A股与具体的股票代码的对应关系如下:
141 |
142 | - 00开头,深证主板A股;30开头,深证创业板
143 | - 60开头,上证主板A股;68开头,上证科创版
144 | - 43、83、87开头,北证A股
145 |
146 | **B股:**
147 |
148 | - 20开头,深证B股
149 | - 90开头,上证B股
150 |
151 | ### 企业年龄
152 |
153 | 1. AGE1 = 企业从成立年份到观测年份的年龄
154 | 2. AGE2 = 企业从上市年份到观测年份的年龄
155 |
156 | ### 市场价值
157 |
158 | 1. 市值A = A股\*今收盘价A股当期值 + 境内上市的外资股B股\*今收盘价B股当期值(沪市\*CNY_USD, 深市/HKD_CNY, 转化为人民币) + (总股数-人民币普通股-境内上市的外资股B股) \* (所有者权益合计期末值/实收资本本期期末值) + 负债合计本期期末值
159 | 2. 市值B = (总股本-境内上市的外资股B股) \* 今收盘价A股当期值 + 境内上市的外资股B股 \* 今收盘价B股当期值(沪市\*CNY_USD, 深市/HKD_CNY, 转化为人民币) + 负债合计本期期末值
160 |
161 | ### 账面市值比
162 |
163 | 1. 账面市值比A = 资产总计 / 市值A
164 | 2. 账面市值比A = 资产总计 / 市值B
165 |
166 | ### 托宾Q值
167 |
168 | 1. 托宾Q值A = 市值A / 资产总计
169 | 2. 托宾Q值B = 市值A / (资产总计-无形资产净额-商誉净额)
170 | 3. 托宾Q值C = 市值B / 资产总计
171 | 4. 托宾Q值D = 市值B / (资产总计-无形资产净额-商誉净额)
172 |
173 | ## 4. 在Stata中调用数据
174 |
175 | 打开Stata,输入如下代码调用数据(**实测GitHub慢但稳定,Gitee快但不稳定**)。
176 |
177 | ```Stata
178 | *- 从 Gitee 调用数据
179 | copy "https://gitee.com/Shutter_Zor/Commonly-Used-Control-Variables/raw/main/ControlVarsDetail.dta" "ControlVarsDetail.dta"
180 | use "ControlVarsDetail.dta", clear
181 | *- 或者
182 | use "https://gitee.com/Shutter_Zor/Commonly-Used-Control-Variables/raw/main/ControlVarsDetail.dta"
183 |
184 | *- 从 GitHub 调用数据
185 | copy "https://github.com/ShutterZor/Commonly-Used-Control-Variables/raw/main/ControlVarsDetail.dta" "ControlVarsDetail.dta"
186 | use "ControlVarsDetail.dta", clear
187 | *- 或者
188 | use "https://github.com/ShutterZor/Commonly-Used-Control-Variables/raw/main/ControlVarsDetail.dta"
189 | ```
190 |
191 | 如果出现`file not found`之类的错误,意味着网络连接不通畅,可直接将链接复制到浏览器下载。建议开梯子用GitHub的方法下载。
192 |
193 | 数据描述:
194 |
195 | 
196 |
197 | 接下来只需要保存到本地就行,比如:`save controls.dta, replace`。
198 |
199 |
--------------------------------------------------------------------------------