Hi everybody,
I am sure I am not the first person asking this, but after wasting an hour trying to replicate solutions on the internet, I am sick of trial and error (more error than trial). My question is as follows:
In one survey, the subjects had to answer the question which kind of activity they spend their most money on. Every subject could specify up to three types of spending, therefore I have three spending variables for each observation/subject (spending1, spending2, spending3). As there were 9 possible kind of acitivities to choose from, I created a value label SPEND with 9 different values (1 to 9). For example, the value 1 represents "housing", 2 represents "transportation" and 3 represents "multimedia and electronical devices".
I now want to calculate which kind of activity was mentioned the most (no matter if it was mentioned in spending1, spending2 or spending3). Thats what I got so far:
This programm is working (except the line with Problem). However, I know want to export the results into a csv file. I therefore use
The idea was to link the existing labels of SPEND with the new created variables, so that the variable n_use_1 has the label/content of SPEND given value 1, n_use_2 has the label/content of SPEND given value 2 and so forth. If that would be the case, I could simply use the label command in esttab and see the labels of the variables, instead of the names of the variables in my csv file. However, I don't know how to implement that kind of idea, as Scalars are appearently the wrong idea (I'm not even sure if I can get access to a scalar in that kind of way).
I also tried to use something like "legend coeflabels(uselabelnames)" in the esttab command, but it did not work either.
In other programming languages, I would do the following: Save the content (not the integer values, but the strings!) of SPEND into a string array (it has got 9 array fields). Inside the for loop, I would iterate through the string array, so that variable n_use_i gets the label that is on position i in the string. However, I have absolutely no idea how to do that in Stata. I would be glad if anybody could help me.
Thank you very much in advance!
I am sure I am not the first person asking this, but after wasting an hour trying to replicate solutions on the internet, I am sick of trial and error (more error than trial). My question is as follows:
In one survey, the subjects had to answer the question which kind of activity they spend their most money on. Every subject could specify up to three types of spending, therefore I have three spending variables for each observation/subject (spending1, spending2, spending3). As there were 9 possible kind of acitivities to choose from, I created a value label SPEND with 9 different values (1 to 9). For example, the value 1 represents "housing", 2 represents "transportation" and 3 represents "multimedia and electronical devices".
I now want to calculate which kind of activity was mentioned the most (no matter if it was mentioned in spending1, spending2 or spending3). Thats what I got so far:
Code:
quietly label list SPEND scalar uselabelnames = r(names) forvalues i = `r(min)'/`r(k)'{ gen n_spend_`i' = (spending1==`i') + (spending2==`i') + (spending3==`i') label var n_use_`i' uselabelnames(`i') (******PROBLEM****) } estpost tabstat n_spend_*, stats(mean sd min max) columns(statistic) estimates store wayofspending
Code:
esttab wayofusing using source.csv, replace main(mean) aux(sd) label /// b(%9.3f) stats(N, fmt(%9.0g)) /// title ("Ways of spending money")
I also tried to use something like "legend coeflabels(uselabelnames)" in the esttab command, but it did not work either.
In other programming languages, I would do the following: Save the content (not the integer values, but the strings!) of SPEND into a string array (it has got 9 array fields). Inside the for loop, I would iterate through the string array, so that variable n_use_i gets the label that is on position i in the string. However, I have absolutely no idea how to do that in Stata. I would be glad if anybody could help me.
Thank you very much in advance!
Comment