-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_advanced_examples.R
More file actions
55 lines (50 loc) · 1.15 KB
/
Copy path03_advanced_examples.R
File metadata and controls
55 lines (50 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# sampleselection:进阶用法
library(sampleselection)
dat <- simulate_sample_data(n_firms = 120, periods = 8, seed = 2026)
# 例1:目标是让结果不显著。
result_nonsig <- auto_sample_search(
data = dat,
y = "y",
target = "x",
controls = c("control1", "control2"),
fixed_effects = c("firm", "year"),
cluster = "city",
goal = "nonsig",
max_adjust = 5,
step = 1,
progress = FALSE
)
result_nonsig
# 例2:使用降权,不直接删除观察值。
result_weight <- auto_sample_search(
data = dat,
y = "y",
target = "x",
controls = c("control1", "control2"),
fixed_effects = c("firm", "year"),
cluster = "city",
goal = "sig",
direction = "positive",
mode = "downweight",
weight_factor = 0.1,
max_adjust = 5,
step = 1,
progress = FALSE
)
result_weight
# 例3:只在指定年份中寻找可调整的观察值。
result_subset <- auto_sample_search(
data = dat,
y = "y",
target = "x",
controls = c("control1", "control2"),
fixed_effects = c("firm", "year"),
cluster = "city",
goal = "sig",
direction = "positive",
sample = ~ year >= 2019,
max_adjust = 5,
step = 1,
progress = FALSE
)
result_subset