• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Sep 12th, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. library(DeclareDesign)
2. proportion_shy <- .06
3.
4. population <- declare_population(
5.   N = 5000,
6.   # true trump vote (unobservable)
7.   truthful_trump_vote = draw_binary(.45, N),
8.
9.   # shy voter (unobservable)
10.   shy = draw_binary(proportion_shy, N),
11.
12.   # Direct question response (1 if Trump supporter and not shy, 0 otherwise)
13.   Y_direct = as.numeric(truthful_trump_vote == 1 & shy == 0),
14.
15.   # Nonsensitive list experiment items
16.   raise_minimum_wage = draw_binary(.8, N),
17.   repeal_obamacare = draw_binary(.6, N),
18.   ban_assault_weapons = draw_binary(.5, N)
19. )
20.
21. potential_outcomes <- declare_potential_outcomes(
22.   Y_list_Z_0 = raise_minimum_wage + repeal_obamacare + ban_assault_weapons,
23.   Y_list_Z_1 = Y_list_Z_0 + truthful_trump_vote
24. )
25.
26. # Inquiry -----------------------------------------------------------------
27. estimand <- declare_estimand(
28.   proportion_truthful_trump_vote = mean(truthful_trump_vote))
29.
30. # Data Strategy -----------------------------------------------------------
31. sampling <- declare_sampling(n = 500)
32. assignment <- declare_assignment(prob = .5)
33.
34. # Answer Strategy ---------------------------------------------------------
35. estimator_direct <- declare_estimator(
36.   Y_direct ~ 1,
37.   model = lm_robust,
38.   term = "(Intercept)",
39.   estimand = estimand,
40.   label = "direct"
41. )
42.
43. estimator_list <- declare_estimator(Y_list ~ Z,
44.                                     model = difference_in_means,
45.                                     estimand = estimand,
46.                                     label = "list")
47.
48. # Design ------------------------------------------------------------------
49. design <-
50.   population +
51.   potential_outcomes +
52.   sampling +
53.   estimand +
54.   assignment +
55.   declare_reveal(outcome_variables = Y_list) +
56.   estimator_direct +
57.   estimator_list
58.
59. draw_data(design)
60.
61. diagnosis <- diagnose_design(design, sims = 500, bootstrap_sims = FALSE)
62. diagnosis
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top