![]() Here is my crack at a solution: CreateCodebook 1) c(colnames(dF),ĭf = data. I didn't leave blank spaces before the lists of code values etc., but you can make those adjustments yourself. # Variable.Name Variable.Label Answer.Label Answer.Code Variable.Type ![]() # utility function: pad vector with blanks to specified lengthĭd <- ame(`Variable Name`=pad(nm,n),Įxample: xx <- as.(Titanic) I didn't think that one would really want this to be enumerated, so I tested for type of factor instead (but you could substitute the length(u)=length(x) line below if you really want). But every variable of length >0 has some unique values: did you mean "if every value is unique"? Even this definition doesn't necessarily work as expected: in the Titanic data set, the responses are integer, and there happen to be only 22 unique values out of 32 total values. I had an issue with one of your definitions, though: you say "If there are no unique values, it is considered open ended". ![]() I decided to take a crack at this for my own amusement. Sanit_cd sanit_cd sanit_cd Open ended numeric Itn_color itn_color itn_color Open ended numeric Rep("",length(AnswerCode) - 1)) else sapply(dF, class)ĭf = ame(VariableName, VariableLabel, AnswerLabel, AnswerCode, VariableType)ĭistrict_name district_name district_name Open ended characterĬoords_x1 coords_x1 coords_x1 Open ended numericĬoords_x2 coords_x2 coords_x2 Open ended numeric Rep("",length(AnswerCode) - 1)) else colnames(dF) Here is my attempt: CreateCodebook 1) c(colnames(dF), Blank if the Answer Label is not categorical. Answer Code which is the numerical assignment to each category in the Answer Label.If there are no unique values, it is considered open ended Answer Label which is the unique values in theĬolumn.Variable Name which is the name of the column.each column in the data frame is evaluated to produce values for 5 different columns: So far, I've encountered the memisc library which has a function called codebook, but it does not do the same thing as in Stata.įor example, In Stata, the output of the codebook would look like this.(see below - this is what I want) Variable Name Variable Label Answer Label Answer Code Variable Type For example, if you want to get detailed information about a variable, namely, Consumption expenditure from a dataset, use the following command: codebook. I would like to find an equivalent function in R. In Stata I am able to use the codebookout command to create an Excel workbook that saves name, label, and storage type of all the variables in the existing dataset with their corresponding values and value labels.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |