-
Notifications
You must be signed in to change notification settings - Fork 5
/
IPEDS12MoInstrAct02to16.do
102 lines (86 loc) · 4.02 KB
/
IPEDS12MoInstrAct02to16.do
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
set more off
clear all
cls
// Use this code to download, build, and save to the local computer
// data from the 12-MONTH INSTRUCTIONAL ACTIVITY survey at the US DOE's
// Integrated Postsecondary Education Data Stystem.
// Jan/2018: Naiya Patel - Updated to include 2016 datafiles.
// Oct/2017: Naiya Patel - Merge with master branch.
// Oct/2017: Naiya Patel - Original author, initial build.
/*#############################################################################
File maintained at
https://github.com/adamrossnelson/StataIPEDSAll
##############################################################################*/
// Utilizes preckage version of sshnd (interactive file picker)/
// Stable 1.0 version of sshnd documentation available at:
// https://github.com/adamrossnelson/sshnd/tree/1.0
do https://raw.githubusercontent.com/adamrossnelson/sshnd/master/sshnd.do
capture log close // Close stray log files.
log using "$loggbl", append // Append sshnd established log file.
local sp char(13) char(10) char(13) char(10) // Define spacer.
version 13 // Enforce version compatibility.
di c(pwd) // Confrim working directory.
// Loop designed to download zip files and NCES provided Stata do files.
// Stata do files need cleaning (remove stray char (13) + char(10) + char(34)).
forvalues fname= 2002/2016 {
// Copy and unzip data and do files.
// Stata 13 introduced support for copy to work with https.
// Use command -update all- if Stata 13 and copy returns an error.
copy https://nces.ed.gov/ipeds/datacenter/data/EFIA`fname'_Data_Stata.zip .
unzipfile EFIA`fname'_Data_Stata.zip, replace
if `fname' > 2006 & `fname' < 2016 {
import delimited efia`fname'_rv_data_stata.csv, clear
}
else {
import delimited efia`fname'_data_stata.csv, clear
}
//Add isYr index and order the new variable.
gen int isYr = `fname'
order isYr, after (unitid)
// Need to download do file from IPEDS data
copy https://nces.ed.gov/ipeds/datacenter/data/EFIA`fname'_Stata.zip .
unzipfile EFIA`fname'_Stata.zip, replace
// Using scalar command
// Remove "insheet" command designed to import data.
// Remove "save" command designed to save data.
scalar fcontents = fileread("efia`fname'.do")
scalar fcontents = subinstr(fcontents, "insheet", "// insheet", 1)
scalar fcontents = subinstr(fcontents, "save", "// save", .)
// Save edited do file.
scalar byteswritten = filewrite("efia`fname'.do", fcontents, 1)
di "QUIET RUN OF efia`fname'.do" //Provides the user information for log file.
qui do efia`fname' //Quietly run do files
di `sp'
compress
saveold efia`fname'_data_stata.dta, replace version (13)
di `sp'
clear
}
//Loop dta files to assemble panel data set.
use efia2016_data_stata.dta, clear
forvalues yindex = 2015(-1)2002 {
display "`yindex'"
append using "efia`yindex'_data_stata.dta", force
di `sp'
}
// Correct duplicate value labels (which will work with Stata). But causes
// error when using data in other settings (e.g. Python Pandas).
// Documentation: https://stackoverflow.com/a/46038793/9572143
qui labelbook, length(12)
qui return list, all
qui numlabel `r(nuniq)', add
drop x* // Remove imputation variables.
cd .. // Move up file directory level, compress, add notes.
compress // Save resulting panel data set.
label data "PanelBuildInfo: https://github.com/adamrossnelson/StataIPEDSAll/tree/master"
notes _dta: "PanelBuildInfo: https://github.com/adamrossnelson/StataIPEDSAll/tree/master"
notes _dta: "Panel built on `c(current_date)'"
saveold "$dtagbl", replace version(13)
qui {
noi di "#####################################################################"
noi di ""
noi di " Saved $dtagbl"
noi di ""
noi di "######################################################################"
}
log close