-
Notifications
You must be signed in to change notification settings - Fork 5
/
FunctionToScrape990s.R
2549 lines (1668 loc) · 128 KB
/
FunctionToScrape990s.R
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# FUNCTION TO COLLECT DATA FROM XML DOCS ON AWS
## from Jeff Lecy's Open Data for Nonprofit Research
## https://github.com/lecy/Open-Data-for-Nonprofit-Research/tree/master/Open_Nonprofit_Datasets
#
# Arguments:
# url - link to a nonprofits xml page
# form.type - check to ensure data is from the correct form in case of poor data in index file
#
# Return Value:
# one-row data frame containing elements from one nonprofit
scrapeXML <- function( url, form.type )
{
# print( url )
doc <- read_xml( url )
xml_ns_strip( doc )
# check to ensure it is the proper form type
FORM <- xml_text( xml_find_all( doc, "//Return/ReturnHeader/*[contains( name(), 'ReturnType')]" ) )
if( length(FORM) == 0 ){ FORM <- "NOT REPORTED ON 990" }
if( is.null(FORM) ){ FORM <- "NOT REPORTED ON 990" }
if( ! FORM %in% form.type )
{
cat( paste( "Organization is not the correct return type;", "\n",
"Desired: ", form.type, "; Actual Type: ", FORM, "\n",
url, "\n \n", sep="" ) )
return(NULL)
}
#------------------------------------------------------------------------------------------------------------------------
# TO FACILITATE PRODUCTION RULES
zeroPC <- function( var )
{
if( FORMTYPE=="990" )
{
if( length(var) == 0 ){ return("0") }
if( is.na(var) ){ return("0") }
}
return( var )
}
zeroEZ <- function( var )
{
if( FORMTYPE=="990EZ" )
{
if( length(var) == 0 ){ return("0") }
if( is.na(var) ){ return("0") }
}
return( var )
}
zeroALL <- function( var )
{
if( length(var) == 0 ){ return("0") }
if( is.na(var) ){ return("0") }
return( var )
}
#------------------------------------------------------------------------------------------------------------------------
#### FROM NCCS CORE - HEADER DATA
#### Fields here are same for forms of same year (990 & 990EZ post-2013; 990 & 990EZ pre-2013)
## EIN
#### EIN field is the same for all forms
EIN <- xml_text( xml_find_all( doc, "//Return/ReturnHeader/Filer/EIN" ) )
## NAME
V_990NAMEpost2014 <- "//Return/ReturnHeader/Filer/BusinessName/BusinessNameLine1Txt"
V_990NAME_2013 <- "//Return/ReturnHeader/Filer/BusinessName/BusinessNameLine1"
V_990NAMEpre2013 <- "//Return/ReturnHeader/Filer/Name/BusinessNameLine1"
name.xpath <- paste( V_990NAME_2013, V_990NAMEpre2013, V_990NAMEpost2014, sep="|" )
NAME <- xml_text( xml_find_all( doc, name.xpath ) )
## DOING BUSINESS AS
V_990DBApost2013 <- "//Return/ReturnHeader/Filer/BusinessName/BusinessNameLine2Txt"
V_990DBApre2013 <- "//Return/ReturnHeader/Filer/Name/BusinessNameLine2"
dba.xpath <- paste( V_990DBApost2013, V_990DBApre2013, sep="|" )
DBA <- xml_text( xml_find_all( doc, dba.xpath ) )
## FISCAL YEAR
V_990FYRpost2013 <- "//Return/ReturnHeader/TaxYr"
V_990FYRpre2013 <- "//Return/ReturnHeader/TaxYear"
fiscal.year.xpath <- paste( V_990FYRpost2013, V_990FYRpre2013, sep="|" )
FISYR <- xml_text( xml_find_all( doc, fiscal.year.xpath ) )
## STATE
V_990STATEpost2013 <- "//Return/ReturnHeader/Filer/USAddress/StateAbbreviationCd"
V_990STATEpre2013 <- "//Return/ReturnHeader/Filer/USAddress/State"
state.xpath <- paste( V_990STATEpost2013, V_990STATEpre2013, sep="|" )
STATE <- xml_text( xml_find_all( doc, state.xpath ) )
## ADDRESS
V_990ADDRpost2013 <- "//Return/ReturnHeader/Filer/USAddress/AddressLine1Txt"
V_990ADDRpre2013 <- "//Return/ReturnHeader/Filer/USAddress/AddressLine1"
address.xpath <- paste( V_990ADDRpost2013, V_990ADDRpre2013, sep="|" )
ADDRESS <- xml_text( xml_find_all( doc, address.xpath ) )
## CITY
V_990CITYpost2013 <- "//Return/ReturnHeader/Filer/USAddress/CityNm"
V_990CITYpre2013 <- "//Return/ReturnHeader/Filer/USAddress/City"
city.xpath <- paste( V_990CITYpost2013, V_990CITYpre2013, sep="|" )
CITY <- xml_text( xml_find_all( doc, city.xpath ) )
## ZIP CODE
V_990ZIPpost2013 <- "//Return/ReturnHeader/Filer/USAddress/ZIPCd"
V_990ZIPpre2013 <- "//Return/ReturnHeader/Filer/USAddress/ZIPCode"
zip.xpath <- paste( V_990ZIPpost2013, V_990ZIPpre2013, sep="|" )
ZIP <- xml_text( xml_find_all( doc, zip.xpath ) )
## START OF YEAR
V_990SYpost2013 <- "//Return/ReturnHeader/TaxPeriodBeginDt"
V_990SYpre2013 <- "//Return/ReturnHeader/TaxPeriodBeginDate"
start.year.xpath <- paste( V_990SYpost2013, V_990SYpre2013, sep="|" )
STYEAR <- xml_text( xml_find_all( doc, start.year.xpath ) )
## END OF YEAR
V_990EYpost2013 <- "//Return/ReturnHeader/TaxPeriodEndDt"
V_990EYpre2013 <- "//Return/ReturnHeader/TaxPeriodEndDate"
end.year.xpath <- paste( V_990EYpost2013, V_990EYpre2013, sep="|" )
ENDYEAR <- xml_text( xml_find_all( doc, end.year.xpath ) )
## TAX PREPARER
V_990TPpost2013 <- "//Return/ReturnHeader/PreparerPersonGrp/PreparerPersonNm"
V_990TPpre2013 <- "//Return/ReturnHeader/Preparer/Name"
tax.prep.xpath <- paste( V_990TPpost2013, V_990TPpre2013, sep="|" )
TAXPREP <- xml_text( xml_find_all( doc, tax.prep.xpath ) )
## TYPE OF TAX FORM
V_990TFpost2013 <- "//Return/ReturnHeader/ReturnTypeCd"
V_990TFpre2013 <- "//Return/ReturnHeader/ReturnType"
tax.form.xpath <- paste( V_990TFpost2013, V_990TFpre2013, sep="|" )
FORMTYPE <- xml_text( xml_find_all( doc, tax.form.xpath ) )
#------------------------------------------------------------------------------------------------------------------------
##### BASIC INFO
## GROSS RECEIPTS
V_990GRCpost2013 <- "//Return/ReturnData/IRS990/GrossReceiptsAmt"
V_990GRCpre2013 <- "//Return/ReturnData/IRS990/GrossReceipts"
V_990GRC.EZpost2013 <- "//Return/ReturnData/IRS990EZ/GrossReceiptsAmt"
V_990GRC.EZpre2013 <- "//Return/ReturnData/IRS990EZ/GrossReceipts"
greceipts.xpath <- paste( V_990GRCpost2013, V_990GRCpre2013, V_990GRC.EZpost2013, V_990GRC.EZpre2013, sep="|" )
GROSSRECEIPTS <- xml_text( xml_find_all( doc, greceipts.xpath ) )
GROSSRECEIPTS <- zeroALL( GROSSRECEIPTS )
## GROUP RETURNS
V_990GRTpost2013 <- "//Return/ReturnData/IRS990/GroupReturnForAffiliatesInd"
V_990GRTpre2013 <- "//Return/ReturnData/IRS990/GroupReturnForAffiliates"
greturn.xpath <- paste( V_990GRTpost2013, V_990GRTpre2013, sep="|" )
GROUPRETURN <- xml_text( xml_find_all( doc, greturn.xpath ) )
## GROUP EXEMPTION NUMBER
V_990GENpost2013 <- "//Return/ReturnData/IRS990/GroupExemptionNum"
V_990GENpre2013 <- "//Return/ReturnData/IRS990/GroupExemptionNumber"
V_990GEN.EZpost2013 <- "//Return/ReturnData/IRS990EZ/GroupExemptionNum"
V_990GEN.EZpre2013 <- "//Return/ReturnData/IRS990EZ/GroupExemptionNumber"
gexempt.number.xpath <- paste( V_990GENpost2013, V_990GENpre2013, V_990GEN.EZpost2013, V_990GEN.EZpre2013, sep="|" )
GROUPEXEMPTNUM <- xml_text( xml_find_all( doc, gexempt.number.xpath ) )
## FORM YEAR
V_990FORMYRpost2013 <- "//Return/ReturnData/IRS990/FormationYr"
V_990FORMYRpre2013 <- "//Return/ReturnData/IRS990/YearFormation"
form.year.xpath <- paste( V_990FORMYRpost2013, V_990FORMYRpre2013, sep="|" )
FORMYEAR <- xml_text( xml_find_all( doc, form.year.xpath ) )
## STATE OF LEGAL DOMICILE
V_990DOMpost2013 <- "//Return/ReturnData/IRS990/LegalDomicileStateCd"
V_990DOMpre2013 <- "//Return/ReturnData/IRS990/StateLegalDomicile"
domicile.xpath <- paste( V_990DOMpost2013, V_990DOMpre2013, sep="|" )
DOMICILE <- xml_text( xml_find_all( doc, domicile.xpath ) )
DOMICILE <- paste( DOMICILE, collapse=" " )
## WEBSITE
V_990WEBpost2013 <- "//Return/ReturnData/IRS990/WebsiteAddressTxt"
V_990WEBpre2013 <- "//Return/ReturnData/IRS990/WebSite"
V_990WEB.EZpost2013 <- "//Return/ReturnData/IRS990EZ/WebsiteAddressTxt"
V_990WEB.EZpre2013 <- "//Return/ReturnData/IRS990EZ/WebSite"
website.xpath <- paste( V_990WEBpost2013, V_990WEBpre2013, V_990WEB.EZpost2013, V_990WEB.EZpre2013, sep="|" )
WEBSITE <- xml_text( xml_find_all( doc, website.xpath ) )
## URL
URL <- url
## FORM OF ORGANIZATION: represent the 4 possible values, broken out then collapsed
## EZ Values are extrapolated from 990s
## ORGANIZATION IS ASSOCATION
V_990FOApost2013 <- "//Return/ReturnData/IRS990/TypeOfOrganizationAssocInd"
V_990FOApre2013 <- "//Return/ReturnData/IRS990/TypeOfOrganizationAssociation"
V_990FOA.EZpost2013 <- "//Return/ReturnData/IRS990EZ/TypeOfOrganizationAssocInd"
V_990FOA.EZpre2013 <- "//Return/ReturnData/IRS990EZ/TypeOfOrganizationAssociation"
type.org.assoc.xpath <- paste( V_990FOApost2013, V_990FOApre2013, V_990FOA.EZpost2013, V_990FOA.EZpre2013, sep="|" )
FORMORGASSOC <- xml_text( xml_find_all( doc, type.org.assoc.xpath ) )
FORMORGASSOC[ length( FORMORGASSOC ) == 0] <- NA
if( is.na( FORMORGASSOC ) == FALSE ) { FORMORGASSOC <- "Association" }
## ORGANIZATION IS CORPORATION
V_990FOCpost2013 <- "//Return/ReturnData/IRS990/TypeOfOrganizationCorpInd"
V_990FOCpre2013 <- "//Return/ReturnData/IRS990/TypeOfOrganizationCorporation"
V_990FOC.EZpost2013 <- "//Return/ReturnData/IRS990EZ/TypeOfOrganizationCorpInd"
V_990FOC.EZpre2013 <- "//Return/ReturnData/IRS990EZ/TypeOfOrganizationCorporation"
type.org.corp.xpath <- paste( V_990FOCpost2013, V_990FOCpre2013, V_990FOC.EZpost2013, V_990FOC.EZpre2013, sep="|" )
FORMORGCORP <- xml_text( xml_find_all( doc, type.org.corp.xpath ) )
FORMORGCORP[ length( FORMORGCORP ) == 0] <- NA
if( is.na( FORMORGCORP ) == FALSE ) { FORMORGCORP <- "Corporation" }
## ORGANIZATION IS TRUST
V_990FOTpost2013 <- "//Return/ReturnData/IRS990/TypeOfOrganizationTrustInd"
V_990FOTpre2013 <- "//Return/ReturnData/IRS990/TypeOfOrganizationTrust"
V_990FOT.EZpost2013 <- "//Return/ReturnData/IRS990EZ/TypeOfOrganizationTrustInd"
V_990FOT.EZpre2013 <- "//Return/ReturnData/IRS990EZ/TypeOfOrganizationTrust"
type.org.trust.xpath <- paste( V_990FOTpost2013, V_990FOTpre2013, V_990FOT.EZpost2013, V_990FOT.EZpre2013, sep="|" )
FORMORGTRUST <- xml_text( xml_find_all( doc, type.org.trust.xpath ) )
FORMORGTRUST[ length( FORMORGTRUST ) == 0] <- NA
if( is.na( FORMORGTRUST ) == FALSE ) { FORMORGTRUST <- "Trust" }
## ORGANIZATION IS OTHER (CHECK BOX)
V_990FOOpost2013 <- "//Return/ReturnData/IRS990/TypeOfOrganizationOtherInd"
V_990FOOpre2013 <- "//Return/ReturnData/IRS990/TypeOfOrganizationOther"
V_990FOO.EZpost2013 <- "//Return/ReturnData/IRS990EZ/TypeOfOrganizationOtherInd"
V_990FOO.EZpre2013 <- "//Return/ReturnData/IRS990EZ/TypeOfOrganizationOther"
type.org.other.xpath <- paste( V_990FOOpost2013, V_990FOOpre2013, V_990FOO.EZpost2013, V_990FOO.EZpre2013, sep="|" )
FORMORGOTHER <- xml_text( xml_find_all( doc, type.org.other.xpath ) )
FORMORGOTHER[ length( FORMORGOTHER ) == 0] <- NA
if( is.na( FORMORGOTHER ) == FALSE ) { FORMORGOTHER <- "" }
## WRITTEN-IN DESCRIPTION OF ORGANIZATION:OTHER
V_990FOWpost2013 <- "//Return/ReturnData/IRS990/OtherOrganizationDsc"
V_990FOWpre2013 <- "//Return/ReturnData/IRS990/TypeOfOrgOtherDescription"
V_990FOW.EZpost2013 <- "//Return/ReturnData/IRS990EZ/OtherOrganizationDsc"
V_990FOW.EZpre2013 <- "//Return/ReturnData/IRS990EZ/TypeOfOrgOtherDescription"
type.org.written.xpath <- paste( V_990FOWpost2013, V_990FOWpre2013, V_990FOW.EZpost2013, V_990FOW.EZpre2013, sep="|" )
FORMORGOTHERDESC <- xml_text( xml_find_all( doc, type.org.written.xpath ) )
## FORM OF ORGANIZATION (COLLAPSED)
FORMORG <- gsub( "NA", "", paste( FORMORGASSOC, FORMORGCORP, FORMORGTRUST, FORMORGOTHER, FORMORGOTHERDESC, sep="" ) )
FORMORG[ FORMORG == "" ] <- NA
## ACCOUNTING METHODS: represent the 3 possible values, broken out then collapsed
## ACCRUAL ACCOUNTING METHOD
V_990AMApost2013 <- "//Return/ReturnData/IRS990/MethodOfAccountingAccrualInd"
V_990AMApre2013 <- "//Return/ReturnData/IRS990/MethodOfAccountingAccrual"
V_990AMA.EZpost2013 <- "//Return/ReturnData/IRS990EZ/MethodOfAccountingAccrualInd"
V_990AMA.EZpre2013 <- "//Return/ReturnData/IRS990EZ/MethodOfAccountingAccrual"
accounting.accrual.xpath <- paste( V_990AMApost2013, V_990AMApre2013, V_990AMA.EZpost2013, V_990AMA.EZpre2013, sep="|" )
ACCTACCRUAL <- xml_text( xml_find_all( doc, accounting.accrual.xpath ) )
ACCTACCRUAL[ length( ACCTACCRUAL ) == 0] <- NA
if( is.na( ACCTACCRUAL ) == FALSE ) { ACCTACCRUAL <- "Accrual" }
## CASH ACCOUNTING METHOD
V_990AMCpost2013 <- "//Return/ReturnData/IRS990/MethodOfAccountingCashInd"
V_990AMCpre2013 <- "//Return/ReturnData/IRS990/MethodOfAccountingCash"
V_990AMC.EZpost2013 <- "//Return/ReturnData/IRS990EZ/MethodOfAccountingCashInd"
V_990AMC.EZpre2013 <- "//Return/ReturnData/IRS990EZ/MethodOfAccountingCash"
accounting.cash.xpath <- paste( V_990AMCpost2013, V_990AMCpre2013, V_990AMC.EZpost2013, V_990AMC.EZpre2013, sep="|" )
ACCTCASH <- xml_text( xml_find_all( doc, accounting.cash.xpath ) )
ACCTCASH[ length( ACCTCASH ) == 0] <- NA
if( is.na( ACCTCASH ) == FALSE ) { ACCTCASH <- "Cash" }
## OTHER ACCOUNTING METHOD
## Should return a string, not an "X" indicating checkbox
V_990AMOpost2013 <- "//Return/ReturnData/IRS990/MethodOfAccountingOtherInd/@methodOfAccountingOtherDesc"
V_990AMOpre2013 <- "//Return/ReturnData/IRS990/MethodOfAccountingOther/@note"
V_990AMO.EZpost2013 <- "//Return/ReturnData/IRS990EZ/MethodOfAccountingOtherDesc"
V_990AMO.EZpre2013 <- "//Return/ReturnData/IRS990EZ/MethodOfAccountingOther"
accounting.other.xpath <- paste( V_990AMOpost2013, V_990AMOpre2013, V_990AMO.EZpost2013, V_990AMO.EZpre2013, sep="|" )
ACCTOTHER <- xml_text( xml_find_all( doc, accounting.other.xpath ) )
ACCTOTHER[ length( ACCTOTHER ) == 0] <- NA
## ACCOUNTING METHOD (COLLAPSED)
ACCTMETHOD <- gsub( "NA", "", paste( ACCTACCRUAL, ACCTCASH, ACCTOTHER, sep="" ) )
ACCTMETHOD[ ACCTMETHOD == "" ] <- NA
## TAX EXEMPT STATUS: represent the 5 possible values, broken out then collapsed
## EXEMPT STATUS 4947(a)(1)
V_990.4947post2013 <- "//Return/ReturnData/IRS990/Organization4947a1NotPFInd"
V_990.4947pre2013 <- "//Return/ReturnData/IRS990/Organization4947a1"
V_990.4947.EZpost2013 <- "//Return/ReturnData/IRS990EZ/Organization4947a1NotPFInd"
V_990.4947.EZpre2013 <- "//Return/ReturnData/IRS990EZ/Organization4947a1"
exempt.4947.xpath <- paste( V_990.4947post2013, V_990.4947pre2013, V_990.4947.EZpost2013, V_990.4947.EZpre2013, sep="|" )
EXEMPT4947A1 <- xml_text( xml_find_all( doc, exempt.4947.xpath ) )
EXEMPT4947A1[ length( EXEMPT4947A1 ) == 0] <- NA
if( is.na( EXEMPT4947A1 ) == FALSE) { EXEMPT4947A1 <- "4947a1" }
## EXEMPT STATUS 501(c)(other than 3)
V_990.501Cpost2013 <- "//Return/ReturnData/IRS990/Organization501cInd"
V_990.501Cpre2013 <- "//Return/ReturnData/IRS990/Organization501c"
V_990.501C.EZpost2013 <- "//Return/ReturnData/IRS990EZ/Organization501cInd"
V_990.501C.EZpre2013 <- "//Return/ReturnData/IRS990EZ/Organization501c"
exempt.501c.xpath <- paste( V_990.501Cpost2013, V_990.501Cpre2013, V_990.501C.EZpost2013, V_990.501C.EZpre2013, sep="|" )
EXEMPT501C <- xml_text( xml_find_all( doc, exempt.501c.xpath ) )
EXEMPT501C[ length( EXEMPT501C ) == 0] <- NA
if( is.na( EXEMPT501C ) == FALSE ) { EXEMPT501C <- "501c" }
## NUMBER OF EXEMPT STATUS 501(c)(other than 3)
V_990.501C.NUMpost2013 <- "//Return/ReturnData/IRS990/Organization501cInd/@organization501cTypeTxt"
V_990.501C.NUMpre2013 <- "//Return/ReturnData/IRS990/Organization501c/@typeOf501cOrganization"
V_990.501C.NUM.EZpost2013 <- "//Return/ReturnData/IRS990EZ/Organization501cInd/@organization501cTypeTxt"
V_990.501C.NUM.EZpre2013 <- "//Return/ReturnData/IRS990EZ/Organization501c/@typeOf501cOrganization"
exempt.num.xpath <- paste( V_990.501C.NUMpost2013, V_990.501C.NUMpre2013, V_990.501C.NUM.EZpost2013, V_990.501C.NUM.EZpre2013, sep="|" )
EXEMPT501CNUM <- xml_text( xml_find_all( doc, exempt.num.xpath ) )
## EXEMPT STATUS 501(c)(3)
V_990.501C.3post2013 <- "//Return/ReturnData/IRS990/Organization501c3Ind"
V_990.501C.3pre2013 <- "//Return/ReturnData/IRS990/Organization501c3"
V_990.501C.3.EZpost2013 <- "//Return/ReturnData/IRS990EZ/Organization501c3Ind"
V_990.501C.3.EZpre2013 <- "//Return/ReturnData/IRS990EZ/Organization501c3"
exempt.501c.3.xpath <- paste( V_990.501C.3post2013, V_990.501C.3pre2013, V_990.501C.3.EZpost2013, V_990.501C.3.EZpre2013, sep="|" )
EXEMPT501C3 <- xml_text( xml_find_all( doc, exempt.501c.3.xpath ) )
EXEMPT501C3[ length( EXEMPT501C3 ) == 0] <- NA
if( is.na( EXEMPT501C3 ) == FALSE ) { EXEMPT501C3 <- "501c3" }
## EXEMPT STATUS 527
V_990.527post2013 <- "//Return/ReturnData/IRS990/Organization527Ind"
V_990.527pre2013 <- "//Return/ReturnData/IRS990/Organization527"
V_990.527.EZpost2013 <- "//Return/ReturnData/IRS990EZ/Organization527Ind"
V_990.527.EZpre2013 <- "//Return/ReturnData/IRS990EZ/Organization527"
exempt.527.xpath <- paste( V_990.527post2013, V_990.527pre2013, V_990.527.EZpost2013, V_990.527.EZpre2013, sep="|" )
EXEMPT527 <- xml_text( xml_find_all( doc, exempt.527.xpath ) )
EXEMPT527[ length( EXEMPT527 ) == 0] <- NA
if( is.na( EXEMPT527 ) == FALSE ) { EXEMPT527 <- "527" }
## EXEMPT STATUS COLLAPSED
EXEMPTSTATUS <- gsub( "NA", "", paste( EXEMPT4947A1, EXEMPT501C, EXEMPT501CNUM, EXEMPT501C3, EXEMPT527, sep="" ) )
EXEMPTSTATUS[ EXEMPTSTATUS == "" ] <- NA
#------------------------------------------------------------------------------------------------------------------------
##### PART I - ACTIVITIES AND GOVERNANCE
## MISSION
V_990Mpost2013 <- "//Return/ReturnData/IRS990/ActivityOrMissionDesc"
V_990Mpre2013 <- "//Return/ReturnData/IRS990/ActivityOrMissionDescription"
V_990M.EZpost2013 <- "//Return/ReturnData/IRS990EZ/PrimaryExemptPurposeTxt"
V_990M.EZpre2013 <- "//Return/ReturnData/IRS990EZ/PrimaryExemptPurpose"
mission.xpath <- paste( V_990Mpost2013, V_990Mpre2013, V_990M.EZpost2013, V_990M.EZpre2013, sep="|" )
MISSION <- xml_text( xml_find_all( doc, mission.xpath ) )
## DISCONTINUED OPERATIONS OR DISPOSAL OF >25% ASSETS
## Double-check this xpath
V_990DOpost2013 <- "//Return/ReturnData/IRS990/ContractTerminationInd"
V_990DOpre2013 <- "//Return/ReturnData/IRS990/TerminationOrContraction"
discontinued.ops.xpath <- paste( V_990DOpost2013, V_990DOpre2013, sep="|" )
DISCOPS <- xml_text( xml_find_all( doc, discontinued.ops.xpath ) )
## VOTING MEMBERS
V_990VMpost2013 <- "//Return/ReturnData/IRS990/VotingMembersGoverningBodyCnt"
V_990VMpre2013 <- "//Return/ReturnData/IRS990/NbrVotingMembersGoverningBody"
voting.mbrs.xpath <- paste( V_990VMpost2013, V_990VMpre2013, sep="|" )
VOTINGMEMBERS <- xml_text( xml_find_all( doc, voting.mbrs.xpath ) )
## INDEPENDENT VOTING MEMBERS
V_990IVMpost2013 <- "//Return/ReturnData/IRS990/VotingMembersIndependentCnt"
V_990IVMpre2013 <- "//Return/ReturnData/IRS990/NbrIndependentVotingMembers"
indvoting.mbrs.xpath <- paste( V_990IVMpost2013, V_990IVMpre2013, sep="|" )
INDVOTINGMEMBERS <- xml_text( xml_find_all( doc, indvoting.mbrs.xpath ) )
## TOTAL EMPLOYEE COUNT
V_990TEpost2013 <- "//Return/ReturnData/IRS990/TotalEmployeeCnt"
V_990TEpre2013 <- "//Return/ReturnData/IRS990/TotalNbrEmployees"
tot.employee.xpath <- paste( V_990TEpost2013, V_990TEpre2013, sep="|" )
TOTEMPLOYEE <- xml_text( xml_find_all( doc, tot.employee.xpath ) )
## TOTAL VOLUNTEER COUNT
V_990TVpost2013 <- "//Return/ReturnData/IRS990/TotalVolunteersCnt"
V_990TVpre2013 <- "//Return/ReturnData/IRS990/TotalNbrVolunteers"
tot.volunteers.xpath <- paste( V_990TVpost2013, V_990TVpre2013, sep="|" )
TOTVOLUNTEERS <- xml_text( xml_find_all( doc, tot.volunteers.xpath ) )
## TOTAL GROSS UBI
V_990TGUpost2013 <- "//Return/ReturnData/IRS990/TotalGrossUBIAmt"
V_990TGUpre2013 <- "//Return/ReturnData/IRS990/TotalGrossUBI"
tot.ubi.xpath <- paste( V_990TGUpost2013, V_990TGUpre2013, sep="|" )
TOTUBI <- xml_text( xml_find_all( doc, tot.ubi.xpath ) )
TOTUBI <- zeroPC( TOTUBI )
## NET UBI
V_990NUpost2013 <- "//Return/ReturnData/IRS990/NetUnrelatedBusTxblIncmAmt"
V_990NUpre2013 <- "//Return/ReturnData/IRS990/NetUnrelatedBusinessTxblIncome"
net.ubi.xpath <- paste( V_990NUpost2013, V_990NUpre2013, sep="|" )
NETUBI <- xml_text( xml_find_all( doc, net.ubi.xpath ) )
NETUBI <- zeroPC( NETUBI )
#------------------------------------------------------------------------------------------------------------------------
##### PART I - REVENUES
## The 990-PC forms split columns in this area into Current Year and Prior Year, the 990-EZs do not. 990-EZ data
## in this section only maps to current year values unless indicated otherwise.
## PRIOR YEAR CONTRIBUTIONS
V_990PCpost2013 <- "//Return/ReturnData/IRS990/ContributionsGrantsPriorYear"
V_990PCpre2013 <- "//Return/ReturnData/IRS990/PYContributionsGrantsAmt"
contrib.prior.xpath <- paste( V_990PCpost2013, V_990PCpre2013, sep="|" )
CONTRIBPRIOR <- xml_text( xml_find_all( doc, contrib.prior.xpath ) )
CONTRIBPRIOR <- zeroPC( CONTRIBPRIOR )
## CURRENT YEAR CONTRIBUTIONS
V_990CCpost2013 <- "//Return/ReturnData/IRS990/CYContributionsGrantsAmt"
V_990CCpre2013 <- "//Return/ReturnData/IRS990/ContributionsGrantsCurrentYear"
V_990CC.EZpost2013 <- "//Return/ReturnData/IRS990EZ/ContributionsGiftsGrantsEtc"
V_990CC.EZpre2013 <- "//Return/ReturnData/IRS990EZ/ContributionsGiftsGrantsEtcAmt"
contrib.current.xpath <- paste( V_990CCpost2013, V_990CCpre2013, V_990CC.EZpost2013, V_990CC.EZpre2013, sep="|" )
CONTRIBCURRENT <- xml_text( xml_find_all( doc, contrib.current.xpath ) )
CONTRIBCURRENT <- zeroALL( CONTRIBCURRENT )
## PRIOR YEAR PROGRAM SERVICE REVENUE
V_990PPSRpost2013 <- "//Return/ReturnData/IRS990/PYProgramServiceRevenueAmt"
V_990PPSRpre2013 <- "//Return/ReturnData/IRS990/ProgramServiceRevenuePriorYear"
psr.prior.xpath <- paste( V_990PPSRpost2013, V_990PPSRpre2013, sep="|" )
PSRPRIOR <- xml_text( xml_find_all( doc, psr.prior.xpath ) )
PSRPRIOR <- zeroPC( PSRPRIOR )
## CURRENT YEAR PROGRAM SERVICE REVENUE
V_990CPSRpost2013 <- "//Return/ReturnData/IRS990/CYProgramServiceRevenueAmt"
V_990CPSRpre2013 <- "//Return/ReturnData/IRS990/ProgramServiceRevenueCY"
V_990CPSR.EZpost2013 <- "//Return/ReturnData/IRS990EZ/ProgramServiceRevenueAmt"
V_990CPSR.EZpre2013 <- "//Return/ReturnData/IRS990EZ/ProgramServiceRevenue"
psr.current.xpath <- paste( V_990CPSRpost2013, V_990CPSRpre2013, V_990CPSR.EZpost2013, V_990CPSR.EZpre2013, sep="|" )
PSRCURRENT <- xml_text( xml_find_all( doc, psr.current.xpath ) )
PSRCURRENT <- zeroALL( PSRCURRENT )
## PRIOR YEAR INVESTMENT INCOME
V_990PIVpost2013 <- "//Return/ReturnData/IRS990/PYInvestmentIncomeAmt"
V_990PIVpre2013 <- "//Return/ReturnData/IRS990/InvestmentIncomePriorYear"
invest.income.prior.xpath <- paste( V_990PIVpost2013, V_990PIVpre2013, sep="|" )
INVINCPRIOR <- xml_text( xml_find_all( doc, invest.income.prior.xpath ) )
INVINCPRIOR <- zeroPC( INVINCPRIOR )
## CURRENT YEAR INVESTMENT INCOME
V_990CIVpost2013 <- "//Return/ReturnData/IRS990/CYInvestmentIncomeAmt"
V_990CIVpre2013 <- "//Return/ReturnData/IRS990/InvestmentIncomeCurrentYear"
V_990CIV.EZpost2013 <- "//Return/ReturnData/IRS990EZ/InvestmentIncomeAmt"
V_990CIV.EZpre2013 <- "//Return/ReturnData/IRS990EZ/InvestmentIncome"
invest.income.current.xpath <- paste( V_990CIVpost2013, V_990CIVpre2013, V_990CIV.EZpost2013, V_990CIV.EZpre2013, sep="|" )
INVINCCURRENT <- xml_text( xml_find_all( doc, invest.income.current.xpath ) )
INVINCCURRENT <- zeroALL( INVINCCURRENT )
## PRIOR YEAR OTHER REVENUE
V_990PORpost2013 <- "//Return/ReturnData/IRS990/PYOtherRevenueAmt"
V_990PORpre2013 <- "//Return/ReturnData/IRS990/OtherRevenuePriorYear"
other.rev.prior.xpath <- paste( V_990PORpost2013, V_990PORpre2013, sep="|" )
OTHERREVPRIOR <- xml_text( xml_find_all( doc, other.rev.prior.xpath ) )
OTHERREVPRIOR <- zeroPC( OTHERREVPRIOR )
## CURRENT YEAR OTHER REVENUE
V_990CORpost2013 <- "//Return/ReturnData/IRS990/CYOtherRevenueAmt"
V_990CORpre2013 <- "//Return/ReturnData/IRS990/OtherRevenueCurrentYear"
V_990CR.EZpost2013 <- "//Return/ReturnData/IRS990EZ/OtherRevenueTotalAmt"
V_990CR.EZpre2013 <- "//Return/ReturnData/IRS990EZ/OtherRevenueTotal"
other.rev.current.xpath <- paste( V_990CORpost2013, V_990CORpre2013, V_990CR.EZpost2013, V_990CR.EZpre2013, sep="|" )
OTHERREVCURRENT <- xml_text( xml_find_all( doc, other.rev.current.xpath ) )
OTHERREVCURRENT <- zeroALL( OTHERREVCURRENT )
## PRIOR YEAR TOTAL REVENUE
V_990PTRpost2013 <- "//Return/ReturnData/IRS990/PYTotalRevenueAmt"
V_990PTRpre2013 <- "//Return/ReturnData/IRS990/TotalRevenuePriorYear"
total.rev.prior.xpath <- paste( V_990PTRpost2013, V_990PTRpre2013, sep="|" )
TOTALREVPRIOR <- xml_text( xml_find_all( doc, total.rev.prior.xpath ) )
TOTALREVPRIOR <- zeroPC( TOTALREVPRIOR )
## CURRENT YEAR TOTAL REVENUE
V_990CTRpost2013 <- "//Return/ReturnData/IRS990/CYTotalRevenueAmt"
V_990CTRpre2013 <- "//Return/ReturnData/IRS990/TotalRevenueCurrentYear"
V_990CTR.EZpost2013 <- "//Return/ReturnData/IRS990EZ/TotalRevenueAmt"
V_990CTR.EZpre2013 <- "//Return/ReturnData/IRS990EZ/TotalRevenue"
total.rev.current.xpath <- paste( V_990CTRpost2013, V_990CTRpre2013, V_990CTR.EZpost2013, V_990CTR.EZpre2013, sep="|" )
TOTALREVCURRENT <- xml_text( xml_find_all( doc, total.rev.current.xpath ) )
TOTALREVCURRENT <- zeroALL( TOTALREVCURRENT )
#------------------------------------------------------------------------------------------------------------------------
##### PART I - REVENUES (990EZ-specific fields)
## Some of the paths here are on the 990 PC but in different areas. They are included here to help
## with mapping across forms. Some of the PC fields here roll up to map to 1 EZ field.
## MEMBERSHIP DUES
V_990MBRDpost2013 <- "//Return/ReturnData/IRS990/MembershipDuesAmt"
V_990MBRDpre2013 <- "//Return/ReturnData/IRS990/MembershipDues"
V_990MBRD.EZpost2013 <- "//Return/ReturnData/IRS990EZ/MembershipDuesAmt"
V_990MBRD.EZpre2013 <- "//Return/ReturnData/IRS990EZ/MembershipDues"
member.dues.xpath <- paste( V_990MBRDpost2013, V_990MBRDpre2013, V_990MBRD.EZpost2013, V_990MBRD.EZpre2013, sep="|" )
MEMBERDUES <- xml_text( xml_find_all( doc, member.dues.xpath ) )
MEMBERDUES <- zeroALL( MEMBERDUES )
## GROSS SALES OF NON-INVENTORY ASSETS
V_990GSNApost2013 <- "//Return/ReturnData/IRS990/GrossAmountSalesAssetsGrp/OtherAmt"
V_990GSNApre2013 <- "//Return/ReturnData/IRS990/GrossAmountSalesAssets/Other"
V_990GSNA.EZpost2013 <- "//Return/ReturnData/IRS990EZ/SaleOfAssetsGrossAmt"
V_990GSNA.EZpre2013 <- "//Return/ReturnData/IRS990EZ/GrossAmountFromSaleOfAssets"
grosssales.nonasset.xpath <- paste( V_990GSNApost2013, V_990GSNApre2013, V_990GSNA.EZpost2013, V_990GSNA.EZpre2013, sep="|" )
GROSSSALESOTHER <- xml_text( xml_find_all( doc, grosssales.nonasset.xpath ) )
GROSSSALESOTHER <- zeroALL( GROSSSALESOTHER )
## COST AND SALES EXPENSES FROM NON-INVENTORY ASSET SALES
V_990TSNApost2013 <- "//Return/ReturnData/IRS990/LessCostOthBasisSalesExpnssGrp/OtherAmt"
V_990TSNApre2013 <- "//Return/ReturnData/IRS990/LessCostOthBasisSalesExpenses/Other"
V_990TSNA.EZpost2013 <- "//Return/ReturnData/IRS990EZ/CostOrOtherBasisExpenseSaleAmt"
V_990TSNA.EZpre2013 <- "//Return/ReturnData/IRS990EZ/CostOtherBasisAndSalesExpenses"
totalsales.nonasset.xpath <- paste( V_990TSNApost2013, V_990TSNApre2013, V_990TSNA.EZpost2013, V_990TSNA.EZpre2013, sep="|" )
SALESCOSTOTHER <- xml_text( xml_find_all( doc, totalsales.nonasset.xpath ) )
SALESCOSTOTHER <- zeroALL( SALESCOSTOTHER )
## NET SALES OF NON-INVENTORY ASSETS
## includes securities for the PC forms
V_990NSNApost2013 <- "//Return/ReturnData/IRS990/NetGainOrLossInvestmentsGrp/TotalRevenueColumnAmt"
V_990NSNApre2013 <- "//Return/ReturnData/IRS990/NetGainOrLossInvestments/TotalRevenueColumn"
V_990NSNA.EZpost2013 <- "//Return/ReturnData/IRS990EZ/GainOrLossFromSaleOfAssetsAmt"
V_990NSNA.EZpre2013 <- "//Return/ReturnData/IRS990EZ/GainOrLossFromSaleOfAssets"
netsales.nonassets.xpath <- paste( V_990NSNApost2013, V_990NSNApre2013, V_990NSNA.EZpost2013, V_990NSNA.EZpre2013, sep="|" )
NETSALESOTHER <- xml_text( xml_find_all( doc, netsales.nonassets.xpath ) )
NETSALESOTHER <- zeroALL( NETSALESOTHER )
## GROSS INCOME FROM GAMING
V_990GIGpost2013 <- "//Return/ReturnData/IRS990/GamingGrossIncomeAmt"
V_990GIGpre2013 <- "//Return/ReturnData/IRS990/GrossIncomeGaming"
V_990GIG.EZpost2013 <- "//Return/ReturnData/IRS990EZ/GamingGrossIncomeAmt"
V_990GIG.EZpre2013 <- "//Return/ReturnData/IRS990EZ/GamingGrossIncome"
grossinc.gaming.xpath <- paste( V_990GIGpost2013, V_990GIGpre2013, V_990GIG.EZpost2013, V_990GIG.EZpre2013, sep="|" )
GROSSINCGAMING <- xml_text( xml_find_all( doc, grossinc.gaming.xpath ) )
GROSSINCGAMING <- zeroALL( GROSSINCGAMING )
## GROSS INCOME FROM FUNDRAISING EVENTS
V_990GIFpost2013 <- "//Return/ReturnData/IRS990/FundraisingGrossIncomeAmt"
V_990GIFpre2013 <- "//Return/ReturnData/IRS990/GrossIncomeFundraisingEvents"
V_990GIF.EZpost2013 <- "//Return/ReturnData/IRS990EZ/FundraisingGrossIncomeAmt"
V_990GIF.EZpre2013 <- "//Return/ReturnData/IRS990EZ/FundraisingGrossIncome"
grossinc.fundrs.xpath <- paste( V_990GIFpost2013, V_990GIFpre2013, V_990GIF.EZpost2013, V_990GIF.EZpre2013, sep="|" )
GROSSINCFNDEVENTS <- xml_text( xml_find_all( doc, grossinc.fundrs.xpath ) )
GROSSINCFNDEVENTS <- zeroALL( GROSSINCFNDEVENTS )
## EXPENSES FROM GAMING EVENTS
## PC only
V_990gamexppost2013 <- "//Return/ReturnData/IRS990/GamingDirectExpensesAmt"
V_990gamexppre2013 <- "//Return/ReturnData/IRS990/GamingDirectExpenses"
gaming.exp.xpath <- paste( V_990gamexppost2013, V_990gamexppre2013, sep="|" )
GAMINGEXP <- xml_text( xml_find_all( doc, gaming.exp.xpath ) )
GAMINGEXP[ length( GAMINGEXP ) == 0 ] <- NA
GAMINGEXP <- zeroPC( GAMINGEXP )
## EXPENSES FROM FUNDRAISING EVENTS
## PC only
V_990fndexppost2013 <- "//Return/ReturnData/IRS990/FundraisingDirectExpensesAmt"
V_990fndexppre2013 <- "//Return/ReturnData/IRS990/FundraisingDirectExpenses"
fnd.events.exp.xpath <- paste( V_990fndexppost2013, V_990fndexppre2013, sep="|" )
FNDEVENTSEXP <- xml_text( xml_find_all( doc, fnd.events.exp.xpath ) )
FNDEVENTSEXP[ length( FNDEVENTSEXP ) == 0] <- NA
FNDEVENTSEXP <- zeroPC( FNDEVENTSEXP )
## EXPENSES FROM GAMING AND FUNDRAISING EVENTS
if( FORMTYPE == "990EZ" ){
V_990EGF.EZpost2013 <- "//Return/ReturnData/IRS990EZ/SpecialEventsDirectExpensesAmt"
V_990EGF.EZpre2013 <- "//Return/ReturnData/IRS990EZ/SpecialEventsDirectExpenses"
exp.gaming.fundrs.xpath <- paste( V_990EGF.EZpost2013, V_990EGF.EZpre2013, sep="|" )
EXPGAMINGFNDEVENTS <- xml_text( xml_find_all( doc, exp.gaming.fundrs.xpath ) )
} else if( FORMTYPE == "990" ){
EXPGAMINGFNDEVENTS <- sum( as.numeric( GAMINGEXP ), as.numeric( FNDEVENTSEXP ), na.rm=T )
}
EXPGAMINGFNDEVENTS <- as.character( EXPGAMINGFNDEVENTS )
EXPGAMINGFNDEVENTS <- zeroALL( EXPGAMINGFNDEVENTS )
## NET GAIN OR LOSS FROM GAMING EVENTS
## PC only
V_990totrevgampost2013 <- "//Return/ReturnData/IRS990/NetIncomeFromGamingGrp/TotalRevenueColumnAmt"
V_990totrevgampre2013 <- "//Return/ReturnData/IRS990/NetIncomeFromGaming/TotalRevenueColumn"
gaming.net.xpath <- paste( V_990totrevgampost2013, V_990totrevgampre2013, sep="|" )
GAMINGNET <- xml_text( xml_find_all( doc, gaming.net.xpath ) )
GAMINGNET[ length( GAMINGNET ) == 0] <- NA
GAMINGNET <- zeroPC( GAMINGNET )
## NET GAIN OR LOSS FROM FUNDRAISING EVENTS
## PC only
V_990totrevfndpost2013 <- "//Return/ReturnData/IRS990/NetIncmFromFundraisingEvtGrp/TotalRevenueColumnAmt"
V_990totrevfndpre2013 <- "//Return/ReturnData/IRS990/NetIncomeFromFundraisingEvents/TotalRevenueColumn"
fnd.events.net.xpath <- paste( V_990totrevfndpost2013, V_990totrevfndpre2013, sep="|" )
FNDEVENTSNET <- xml_text( xml_find_all( doc, fnd.events.net.xpath ) )
FNDEVENTSNET[ length( FNDEVENTSNET ) == 0] <- NA
FNDEVENTSNET <- zeroPC( FNDEVENTSNET )
## NET DIFFERENCE FOR GAMING AND FUNDRAISING EVENTS
if( FORMTYPE == "990EZ" ){
V_990NGF.EZpost2013 <- "//Return/ReturnData/IRS990EZ/SpecialEventsNetIncomeLossAmt"
V_990NGF.EZpre2013 <- "//Return/ReturnData/IRS990EZ/SpecialEventsNetIncomeLoss"
net.gaming.fundrs.xpath <- paste( V_990NGF.EZpost2013, V_990NGF.EZpre2013, sep="|" )
NETGAMINGFNDEVENTS <- xml_text( xml_find_all( doc, net.gaming.fundrs.xpath ) )
} else if( FORMTYPE == "990" ){
NETGAMINGFNDEVENTS <- sum( as.numeric( GAMINGNET ), as.numeric( FNDEVENTSNET ), na.rm=T )
}
NETGAMINGFNDEVENTS <- as.character( NETGAMINGFNDEVENTS )
NETGAMINGFNDEVENTS <- zeroALL( NETGAMINGFNDEVENTS )
## GROSS SALES OF INVENTORY ASSETS
V_990GSIpost2013 <- "//Return/ReturnData/IRS990/GrossSalesOfInventoryAmt"
V_990GSIpre2013 <- "//Return/ReturnData/IRS990/GrossSalesOfInventory"
V_990GSI.EZpost2013 <- "//Return/ReturnData/IRS990EZ/GrossSalesOfInventoryAmt"
V_990GSI.EZpre2013 <- "//Return/ReturnData/IRS990EZ/GrossSalesOfInventory"
gross.salesinv.xpath <- paste( V_990GSIpost2013, V_990GSIpre2013, V_990GSI.EZpost2013, V_990GSI.EZpre2013, sep="|" )
GROSSSALESINV <- xml_text( xml_find_all( doc, gross.salesinv.xpath ) )
GROSSSALESINV <- zeroALL( GROSSSALESINV )
## COST OF GOODS SOLD
V_990CSIpost2013 <- "//Return/ReturnData/IRS990/CostOfGoodsSoldAmt"
V_990CSIpre2013 <- "//Return/ReturnData/IRS990/CostOfGoodsSold"
V_990CSI.EZpost2013 <- "//Return/ReturnData/IRS990EZ/CostOfGoodsSoldAmt"
V_990CSI.EZpre2013 <- "//Return/ReturnData/IRS990EZ/CostOfGoodsSold"
cost.salesinv.xpath <- paste( V_990CSIpost2013, V_990CSIpre2013, V_990CSI.EZpost2013, V_990CSI.EZpre2013, sep="|" )
SALESCOSTINV <- xml_text( xml_find_all( doc, cost.salesinv.xpath ) )
SALESCOSTINV <- zeroALL( SALESCOSTINV )
## NET DIFFERENCE OF SALES MINUS COST OF GOODS
V_990NSIpost2013 <- "//Return/ReturnData/IRS990/NetIncomeOrLossGrp/TotalRevenueColumnAmt"
V_990NSIpre2013 <- "//Return/ReturnData/IRS990/NetIncomeOrLoss/TotalRevenueColumn"
V_990NSI.EZpost2013 <- "//Return/ReturnData/IRS990EZ/GrossProfitLossSlsOfInvntryAmt"
V_990NSI.EZpre2013 <- "//Return/ReturnData/IRS990EZ/GroProfitLossSalesOfInventory"
net.salesinv.xpath <- paste( V_990NSIpost2013, V_990NSIpre2013, V_990NSI.EZpost2013, V_990NSI.EZpre2013, sep="|" )
NETSALESINV <- xml_text( xml_find_all( doc, net.salesinv.xpath ) )
NETSALESINV <- zeroALL( NETSALESINV )
#------------------------------------------------------------------------------------------------------------------------
##### PART I - EXPENSES
## The 990-PC forms split columns in this area into Current Year and Prior Year, the 990-EZs do not. 990-EZ data
## in this section only maps to current year values unless indicated otherwise.
## PRIOR YEAR GRANTS PAID
V_990PGPpost2013 <- "//Return/ReturnData/IRS990/PYGrantsAndSimilarPaidAmt"
V_990PGPpre2013 <- "//Return/ReturnData/IRS990/GrantsAndSimilarAmntsPriorYear"
grants.paid.prior.xpath <- paste( V_990PGPpost2013, V_990PGPpre2013, sep="|" )
GRANTSPAIDPRIOR <- xml_text( xml_find_all( doc, grants.paid.prior.xpath ) )
GRANTSPAIDPRIOR <- zeroPC( GRANTSPAIDPRIOR )
## CURRENT YEAR GRANTS PAID
V_990CGPpost2013 <- "//Return/ReturnData/IRS990/CYGrantsAndSimilarPaidAmt"
V_990CGPpre2013 <- "//Return/ReturnData/IRS990/GrantsAndSimilarAmntsCY"
V_990CGP.EZpost2013 <- "//Return/ReturnData/IRS990EZ/GrantsAndSimilarAmountsPaidAmt"
V_990CGP.EZpre2013 <- "//Return/ReturnData/IRS990EZ/GrantsAndSimilarAmountsPaid"
grants.paid.current.xpath <- paste( V_990CGPpost2013, V_990CGPpre2013, V_990CGP.EZpost2013, V_990CGP.EZpre2013, sep="|" )
GRANTSPAIDCURRENT <- xml_text( xml_find_all( doc, grants.paid.current.xpath ) )
GRANTSPAIDCURRENT <- zeroALL( GRANTSPAIDCURRENT )
## PRIOR YEAR BENEFITS PAID TO OR FOR MEMBERS
V_990PBPpost2013 <- "//Return/ReturnData/IRS990/PYBenefitsPaidToMembersAmt"
V_990PBPpre2013 <- "//Return/ReturnData/IRS990/BenefitsPaidToMembersPriorYear"
benefits.paid.prior.xpath <- paste( V_990PGPpost2013, V_990PGPpre2013, sep="|" )
MEMBERBENPRIOR <- xml_text( xml_find_all( doc, benefits.paid.prior.xpath ) )
MEMBERBENPRIOR <- zeroPC( MEMBERBENPRIOR )
## CURRENT YEAR BENEFITS PAID TO OR FOR MEMBERS
V_990CBPpost2013 <- "//Return/ReturnData/IRS990/CYBenefitsPaidToMembersAmt"
V_990CBPpre2013 <- "//Return/ReturnData/IRS990/BenefitsPaidToMembersCY"
V_990CBP.EZpost2013 <- "//Return/ReturnData/IRS990EZ/BenefitsPaidToOrForMembersAmt"
V_990CBP.EZpre2013 <- "//Return/ReturnData/IRS990EZ/BenefitsPaidToOrForMembers"
benefits.paid.current.xpath <- paste( V_990CBPpost2013, V_990CBPpre2013, V_990CBP.EZpost2013, V_990CBP.EZpre2013, sep="|" )
MEMBERBENCURRENT <- xml_text( xml_find_all( doc, benefits.paid.current.xpath ) )
MEMBERBENCURRENT <- zeroALL( MEMBERBENCURRENT )
## PRIOR YEAR SALARIES PAID
V_990PSPpost2013 <- "//Return/ReturnData/IRS990/PYSalariesCompEmpBnftPaidAmt"
V_990PSPpre2013 <- "//Return/ReturnData/IRS990/SalariesEtcPriorYear"
salaries.prior.xpath <- paste( V_990PSPpre2013, V_990PSPpost2013, sep="|" )
SALARIESPRIOR <- xml_text( xml_find_all( doc, salaries.prior.xpath ) )
SALARIESPRIOR <- zeroPC( SALARIESPRIOR )
## CURRENT YEAR SALARIES PAID
V_990CSPpost2013 <- "//Return/ReturnData/IRS990/CYSalariesCompEmpBnftPaidAmt"
V_990CSPpre2013 <- "//Return/ReturnData/IRS990/SalariesEtcCurrentYear"
V_990CSP.EZpost2013 <- "//Return/ReturnData/IRS990EZ/SalariesOtherCompEmplBnftAmt"
V_990CSP.EZpre2013 <- "//Return/ReturnData/IRS990EZ/SalariesOtherCompEmplBenefits"
salaries.current.xpath <- paste( V_990CSPpost2013, V_990CSPpre2013, V_990CSP.EZpost2013, V_990CSP.EZpre2013, sep="|" )
SALARIESCURRENT <- xml_text( xml_find_all( doc, salaries.current.xpath ) )
SALARIESCURRENT <- zeroALL( SALARIESCURRENT )
## PRIOR YEAR PROFESSIONAL FUNDRAISING FEES
V_990PFFpost2013 <- "//Return/ReturnData/IRS990/PYTotalProfFndrsngExpnsAmt"
V_990PFFpre2013 <- "//Return/ReturnData/IRS990/TotalProfFundrsngExpPriorYear"
profund.fees.prior.xpath <- paste( V_990PFFpre2013, V_990PFFpost2013, sep="|" )
PROFUNDFEESPRIOR <- xml_text( xml_find_all( doc, profund.fees.prior.xpath ) )
PROFUNDFEESPRIOR <- zeroPC( PROFUNDFEESPRIOR )
## CURRENT YEAR PROFESSIONAL FUNDRAISING FEES
V_990CFFpost2013 <- "//Return/ReturnData/IRS990/CYTotalProfFndrsngExpnsAmt"
V_990CFFpre2013 <- "//Return/ReturnData/IRS990/TotalProfFundrsngExpCY"
profund.fees.current.xpath <- paste( V_990CFFpost2013, V_990CFFpre2013, sep="|" )
PROFUNDFEESCURRENT <- xml_text( xml_find_all( doc, profund.fees.current.xpath ) )
PROFUNDFEESCURRENT <- zeroPC( PROFUNDFEESCURRENT )
## TOTAL FUNDRAISING EXPENSES
V_990TFFpost2013 <- "//Return/ReturnData/IRS990/CYTotalFundraisingExpenseAmt"
V_990TFFpre2013 <- "//Return/ReturnData/IRS990/TotalFundrsngExpCurrentYear"
totexp.fundrs.xpath <- paste( V_990TFFpost2013, V_990TFFpre2013, sep="|" )
TOTFUNDEXP <- xml_text( xml_find_all( doc, totexp.fundrs.xpath ) )
TOTFUNDEXP <- zeroPC( TOTFUNDEXP )
## FEES FOR SERVICES are broken out on PC and consolidated in EZ.
## This section consolidates the PC values
## FEES FOR SERVICES: MANAGEMENT
V_990F4S.mgmt.post2013 <- "//Return/ReturnData/IRS990/FeesForServicesManagementGrp/TotalAmt"
V_990F4S.mgmt.pre2013 <- "//Return/ReturnData/IRS990/FeesForServicesManagement/Total"
fees.mgmt.xpath <- paste( V_990F4S.mgmt.post2013, V_990F4S.mgmt.pre2013, sep="|" )
FEESMGMT <- xml_text( xml_find_all( doc, fees.mgmt.xpath ) )
FEESMGMT[ length( FEESMGMT ) == 0] <- NA
FEESMGMT <- zeroPC( FEESMGMT )
## FEES FOR SERVICES: LEGAL
V_990F4S.legal.post2013 <- "//Return/ReturnData/IRS990/FeesForServicesLegalGrp/TotalAmt"
V_990F4S.legal.pre2013 <- "//Return/ReturnData/IRS990/FeesForServicesLegal/Total"
fees.legal.xpath <- paste( V_990F4S.legal.post2013, V_990F4S.legal.pre2013, sep="|" )
FEESLEGAL <- xml_text( xml_find_all( doc, fees.legal.xpath ) )
FEESLEGAL[ length( FEESLEGAL ) == 0] <- NA
FEESLEGAL <- zeroPC( FEESLEGAL )
## FEES FOR SERVICES: ACCOUNTING
V_990F4S.accting.post2013 <- "//Return/ReturnData/IRS990/FeesForServicesAccountingGrp/TotalAmt"
V_990F4S.accting.pre2013 <- "//Return/ReturnData/IRS990/FeesForServicesAccounting/Total"
fees.acct.xpath <- paste( V_990F4S.accting.post2013, V_990F4S.accting.pre2013, sep="|" )
FEESACCT <- xml_text( xml_find_all( doc, fees.acct.xpath ) )
FEESACCT[ length( FEESACCT ) == 0] <- NA
FEESACCT <- zeroPC( FEESACCT )
## FEES FOR SERVICES: LOBBYING
V_990F4S.lobbying.post2013 <- "//Return/ReturnData/IRS990/FeesForServicesLobbyingGrp/TotalAmt"
V_990F4S.lobbying.pre2013 <- "//Return/ReturnData/IRS990/FeesForServicesLobbying/Total"
fees.lobby.xpath <- paste( V_990F4S.lobbying.post2013, V_990F4S.lobbying.pre2013, sep="|" )
FEESLOBBY <- xml_text( xml_find_all( doc, fees.lobby.xpath ) )
FEESLOBBY[ length( FEESLOBBY ) == 0] <- NA
FEESLOBBY <- zeroPC( FEESLOBBY )
## FEES FOR SERVICES: PROFESSIONAL FUNDRAISING
## Should equal PROFUNDFEESCURRENT
V_990F4S.profundserv.post2013 <- "//Return/ReturnData/IRS990/FeesForServicesProfFundraising/TotalAmt"
V_990F4S.profundserv.pre2013 <- "//Return/ReturnData/IRS990/FeesForServicesProfFundraising/Total"
fees.profund.xpath <- paste( V_990F4S.profundserv.post2013, V_990F4S.profundserv.pre2013, sep="|" )
FEESPROFND <- xml_text( xml_find_all( doc, fees.profund.xpath ) )
FEESPROFND[ length( FEESPROFND ) == 0] <- NA
FEESPROFND <- zeroPC( FEESPROFND )
## FEES FOR SERVICES: INVESTMENT MANAGEMENT
V_990F4S.invmgmt.post2013 <- "//Return/ReturnData/IRS990/FeesForSrvcInvstMgmntFeesGrp/TotalAmt"
V_990F4S.invmgmt.pre2013 <- "//Return/ReturnData/IRS990/FeesForServicesInvstMgmntFees/Total"
fees.invmgmt.xpath <- paste( V_990F4S.invmgmt.post2013, V_990F4S.invmgmt.pre2013, sep="|" )
FEESINVMGMT <- xml_text( xml_find_all( doc, fees.invmgmt.xpath ) )
FEESINVMGMT[ length( FEESINVMGMT ) == 0] <- NA
FEESINVMGMT <- zeroPC( FEESINVMGMT )
## FEES FOR SERVICES: OTHER
V_990F4S.other.post2013 <- "//Return/ReturnData/IRS990/FeesForServicesOtherGrp/TotalAmt"
V_990F4S.other.pre2013 <- "//Return/ReturnData/IRS990/FeesForServicesOther/Total"
fees.other.xpath <- paste( V_990F4S.other.post2013, V_990F4S.other.pre2013, sep="|" )
FEESOTHER <- xml_text( xml_find_all( doc, fees.other.xpath ) )
FEESOTHER[ length( FEESOTHER ) == 0] <- NA
FEESOTHER <- zeroPC( FEESOTHER )
## PRO. FEES AND OTHERS TO INDEPENDENT CONTRACTORS
V_990PFID.EZpost2013 <- "//Return/ReturnData/IRS990EZ/FeesAndOtherPymtToIndCntrctAmt"
V_990PFID.EZpre2013 <- "//Return/ReturnData/IRS990EZ/FeesAndOthPymtToIndContractors"
profees.indep.contractors.xpath <- paste( V_990PFID.EZpost2013, V_990PFID.EZpre2013, sep="|" )
PROFEESINDEP <- sum( as.numeric( FEESMGMT ), as.numeric( FEESLEGAL ), as.numeric( FEESACCT ),
as.numeric( FEESLOBBY ), as.numeric( FEESPROFND ), as.numeric( FEESINVMGMT ),