Instantly share code, notes, and snippets.
Last active Nov 23, 2021
readSHARE setup for Stata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instructions for setting up readSHARE in Stata | |
// What is readSHARE? | |
view browse "https://ideas.repec.org/c/boc/bocode/s458405.html" | |
// 2.1. Load all the waves that you want to use in the same folder | |
* In other words, all folders containing the data for a SHARE wave should be found following the same path , for example under "C:/Users/JohnSmith/Documents/SHARE" | |
* Remember to extract the zip-files. | |
* We recommend you download all waves at once | |
// 2.2. Download readSHARE | |
ssc install readSHARE | |
// 2.3. Create the following macros | |
// Check that you do not have whitespace in your paths and the folder names correspond to what you have in your computer | |
global sData "C:/YOUR_DIRECTORY/" // NB! Insert your path here | |
global shareDesc "${sData}/shareDescStata" | |
global w1Dir "${sData}sharew1_rel7-1-0_ALL_datasets_stata/" | |
global w2Dir "${sData}sharew2_rel7-1-0_ALL_datasets_stata/" | |
global w3Dir "${sData}sharew3_rel7-1-0_ALL_datasets_stata/" | |
global w4Dir "${sData}sharew4_rel7-1-0_ALL_datasets_stata/" | |
global w5Dir "${sData}sharew5_rel7-1-0_ALL_datasets_stata/" | |
global w6Dir "${sData}sharew6_rel7-1-0_ALL_datasets_stata/" | |
global w7Dir "${sData}sharew7_rel7-1-1_ALL_datasets_stata/" | |
global w8Dir "${sData}sharew8_rel1-0-0_ALL_datasets_stata/" | |
// First corona survey | |
/* | |
For this to work you will have to do a 2-step workaround (might not be needed if readSHARE is updated in the future) | |
a) change "(sharew)(.)_rel[0-9\-]+_([a-zA-Z0-9_\-]+)\.dta" in row 43 of the ado createSHAREDesc .... | |
.... to "(sharew)(.|..)_rel[0-9\-]+_([a-zA-Z0-9_\-]+)\.dta" | |
After installing readSHARE, you should find the file in C:\ado\plus\c\createsharedesc.ado | |
b) rename the files of the first corona survey from sharew8_ to sharew81_ | |
A quick way to do this in windows is in powershell, mac/linux will have similiar, but easier solutions | |
# In Powershell (you might need administrative priviledges) | |
# make your first corona survey your working directory | |
cd C:\Path\To\sharew8_rel1-0-0_ca_ALL_datasets_stata | |
# change the filenames | |
get-childitem *.dta | foreach { rename-item $_ $_.Name.Replace("sharew8_", "sharew81_") } | |
# for more info, see https://superuser.com/a/578076/962566 | |
*/ | |
global w81Dir "${sData}sharew8_rel1-0-0_ca_ALL_datasets_stata/" | |
// Second corona survey | |
* Should work without changing the names, but you will have to change the line 43 | |
global w91Dir "${sData}sharew91_rel0_ALL_datasets_stata/" // public relase will be out in late 2021/ early 2022 | |
// NB! Run the above global macros every time you use readSHARE | |
*Alternatively you can copy the macros in the profile.do file. That way the macros are active upon startup of Stata | |
*Profile.do file is created or located in your "personal" folder, the path of which can be found using the command | |
personal | |
// you can check that your paths look reasonable by checking your paths using the following commands | |
// often missing "/"'s are causing trouble | |
di "${shareDesc}" | |
di "${sData}" | |
di "${w1Dir}" // etc. | |
// 2.4. Finally create a file containing the metainfo and save it | |
// run the following two lines only once, and uncomment this after that | |
createSHAREDesc, sDir("${sData}") | |
cap n save "${shareDesc}", replace | |
// 2.5. Congratulate yourself for the good work when the following command opens the PH-module of wave 7 | |
readSHARE *, w(7) mod(ph) | |
// 2.6. Also get familiar with the full functionalities of readSHARE | |
help addSHARE | |
help readSHARE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment