Skip to content
This repository has been archived by the owner on Feb 28, 2019. It is now read-only.

Latest commit

 

History

History
53 lines (46 loc) · 1.66 KB

File metadata and controls

53 lines (46 loc) · 1.66 KB
Error in user YAML: (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1
---
title: 'STATA-only' option for DeclareDesign
author: Pete Mohanty
date: October 10th, 2018
---

STATA-only is based on an rclass program, which declares, simulates, and estimates. First, the environment is initialized.

program twoarm, rclass
  version 15
  drop _all
  local N = 100
  set obs `N'

Users could replace the above to use existing data. An example like that show data from auto could be incorporated as covariates can be found here. Next, constants are initialized as locals:

  local assignment_prob  =  0.5
  local control_mean  =  0

Next, vectors corresponding to treatment and control are simulated as STATA variables. Here's another excerpt:

  gen u_0 = rnormal()
  gen Z = runiform() < `assignment_prob'
  gen Y_Z_0 = (1-Z)*(u_0*`control_sd' + `control_mean')

Finally, quantities of interest can be returned like so:

  gen tau = Y_Z_1 - Y_Z_0
  summarize tau
  return scalar estimand = r(mean)
  
  regress Y Z
  local estimate _b[Z]
  return scalar estimate = `estimate'

Here's the simulation command:

simulate estimand = r(estimand) estimate = r(estimate) se = r(se) p = r(p), reps(500): twoarm

A companion do file shows some postestimation commands of interest.

local bias r(estimand) - r(estimate)
display `bias'

summarize estimate
summarize p

gen true_positive = p < 0.05 & sign(estimand) == sign(estimand)
summarize true_positive