libname slapp "C:\Users\shaphanng.SMUSTF\OneDrive - Singapore Management University\Project\SLAPP\LNYZ\data\raw\federal court\fjc";
data slapp;
set slapp.fjc;
if nos = 320;
if judgment =1 or judgment =3 then delete;
if disp = 2 or disp = 3 or disp = 12 or disp = 14 then dismissed = 1;
else dismissed = 0;
if judgment = 2 then favd = 1;
else favd = 0;
if favd =1 or dismissed =1 then slapp =1; *18323;
slapp_dur = termdate-filedate*slapp;
if slapp = 1;
run; *18323;
proc import out=district_key datafile="C:\Users\shaphanng.SMUSTF\OneDrive - Singapore Management University\Project\SLAPP\LNYZ\data\raw\federal court\district_key.dta" dbms=dta replace; run;
proc sql;
 create table fjc_slapp1 as 
select distinct a.*, b.jurisdiction, b.state
from slapp a left join district_key as b
	on a.district = b.code ;
quit; *18323;
**unique cases: docket, office, district;
proc sql;
 create table fjc_slapp1a2 as 
	select distinct docket, office, district, state, filedate, fileyear, max(slapp) as slapp, mean(slapp_dur) as slapp_dur
from fjc_slapp1
group by docket, office, district, filedate, fileyear;
quit; *18303;
proc sql;
 create table fjc_slapp1c as 
	select distinct fileyear, state, sum(slapp) as nslapp, mean(slapp_dur) as slapp_dur
from fjc_slapp1a2 
group by state, fileyear;
quit; *2039;
libname rep "C:\Users\shaphanng.SMUSTF\OneDrive - Singapore Management University\Project\SLAPP\LNYZ\data\replication";
data rep.fjc_libel_dismissed;
set fjc_slapp1c;
run; *2039;
*****calculate total number of libel cases;
data fjc_libel;
set slapp.fjc;
if nos = 320;
run;
*28785;
proc sql;
 create table fjc_libel1 as 
select distinct a.*, b.jurisdiction, b.state
from fjc_libel a left join district_key as b
	on a.district = b.code ;
quit;
proc sql;
 create table fjc_libel1a2 as 
	select distinct docket, office, district, state, filedate, fileyear
from fjc_libel1
group by docket, office, district, filedate, fileyear;
quit; *28741;
proc sql;
 create table fjc_libel1c as 
	select distinct fileyear, state, count(docket) as nlibelfiled
from fjc_libel1a2
group by state, fileyear;
quit; *2182;
*****calculate total number of cases;
proc sql;
 create table fjc as 
select distinct a.*, b.jurisdiction, b.state
from slapp.fjc a left join district_key as b
	on a.district = b.code ;
quit; *10473370;
proc sql;
 create table fjc1 as 
	select distinct docket, office, district, state, filedate, fileyear, plaintiff, defendant
from fjc ;
quit; *10439084;
proc sql;
 create table fjc2b as 
	select distinct docket, office, district, state, filedate, fileyear
from fjc1
group by docket, office, district, filedate, fileyear;
quit; *10431405;
proc sql;
 create table fjc2d as 
	select distinct fileyear, state, count(docket) as nfiled
from fjc2b
group by state, fileyear having not missing(state);
quit; *2883;
proc sql;
 create table rep.fjc_libel_new1 as 
select distinct a.*, b.*, c.*
from fjc2d a left join rep.fjc_libel_dismissed as b
	on a.state = b.state and a.fileyear = b.fileyear
left join fjc_libel1c as c
	on a.state = c.state and a.fileyear = c.fileyear;
quit; *2883;
data rep.fjc_libel_new1;
set rep.fjc_libel_new1;
fileyear1 = fileyear + 0;
if fileyear1 < 30 then year = 2000+fileyear1;
if fileyear1 >=30 then year = 1900+fileyear1;
drop fileyear1;
run;
PROC EXPORT DATA= rep.fjc_libel_new1
    OUTFILE= "C:\Users\shaphanng.SMUSTF\OneDrive - Singapore Management University\Project\SLAPP\LNYZ\data\replication\fjc_libel_new1.dta"
	DBMS= STATA REPLACE;
	RUN;
************************************************;
