Exporting data from CSPro to Stata: variable names too long

Discussions about tools to complement CSPro data processing
Forum rules
New release: CSPro 8.0
Post Reply
elenaba
Posts: 5
Joined: June 20th, 2019, 12:20 pm

Exporting data from CSPro to Stata: variable names too long

Post by elenaba »

Dear CSPro users,

I have a survey data set collected using CSPro by a third party that I want to export to Stata for analysis, but the CSPro datafile contains a large (probably +100) number of variables that have more than 32 characters. Since Stata does not allow variable names of this length, I am not sure how to export the data to Stata.

Changing all the variable names by hand in the CSPro dictionairy seems like a very inefficient solution. I've tried exporting the data to SPSS so as to copy the variable names into the labels and reducing the variable name length using syntax. However, this strategy has so far not worked, because whenever I try to copy the variable names manually from the SPSS Data Viewer, the program crashes. Possibly this happens because the number of variables is huge (over 80 000) ? (This is another problem that needs to be solved later since I am using Stata/SE 15, which allows for only 32 000 variables).

I am completely new to both CSPro and SPSS and therefore have no clue of how to tackle this issue. Any help would be greatly appreciated!
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: Exporting data from CSPro to Stata: variable names too long

Post by aaronw »

We recommend using dictionary macros to copy all the dictionary variables to Excel. Use the following formula in Excel

Code: Select all

=LEFT(E1, 32)
to truncate all variables to 32 and then paste them back to CSPro using the dictionary macros. Now use this dictionary to export.
elenaba
Posts: 5
Joined: June 20th, 2019, 12:20 pm

Re: Exporting data from CSPro to Stata: variable names too long

Post by elenaba »

Thank you for the answer.

I am trying to apply the solution, having used the macro to copy paste all variable names and labels in excel. I have then shortened the variable names as per your suggestion in another sheet, and copy pasted these shortened names into the information copied from the dictionary, thus trying to maintain the exact same format. However, when I try to paste this information back in the dictionary using a macro, I get an error message saying that the clipboard contents do not match the dictionary.

I cannot find details online on how to make sure that the right format is used - any idea what I am doing wrong? Apologies for the very simple questions; I am completely new to CSPro.

Many thanks,

Elena
elenaba
Posts: 5
Joined: June 20th, 2019, 12:20 pm

Re: Exporting data from CSPro to Stata: variable names too long

Post by elenaba »

For those with the same issue: I managed to make the copy pasting work by cleaning the clipboard before copying the data in Excel, and by copying using the 'copy' button in the right click menu instead of Ctr+C. (Not sure if any of these were the actual problem)
elenaba
Posts: 5
Joined: June 20th, 2019, 12:20 pm

Re: Exporting data from CSPro to Stata: variable names too long

Post by elenaba »

Dear users,

I am trying to export the CSPro data to Stata using the adjusted dictionary with shortened variable names. I opened CSPro, chose the Export tool, chose the adjusted dictionary with shortened variable names when prompted to select a file, selected the full dictionary to be exported (one file, all in one record), click on 'run', choose the datafile that needs to be exported, and save the export files (e.g. stata dofile) in a different folder than the datafile.

The program produces the export files, but the Stata dofile contains the original variable names that are too long, and not the shortened ones from the adjusted dictionary. Hence, I cannot run the dofile and produce the Stata dataset. What is going wrong here?

Many thanks for any help,

Elena
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: Exporting data from CSPro to Stata: variable names too long

Post by aaronw »

I would double check the dictionary you are using for the export and verify it contains the shortened names.

I made a simple example and the export is outputting the shortened names. I'll attach the application, so you can try. Variables are field_11, field_22, etc. They will export as field_1, field_2, etc. This application is in the "long-names" folder. The "short-names" folder contains an updated dictionary, export specifications, and the result of the export.

Here is the .do file. The export id is shortened and the export identification hasn't changes as we didn't change the labels.
do.PNG
do.PNG (3.52 KiB) Viewed 4028 times
Attachments
demo-export.zip
(7.04 KiB) Downloaded 244 times
Post Reply