Q:

Stata - Preserving encoded variable and stacked graphing

These data represent ice cream preferences where individuals can change these preferences over time
id      time   flavor_str     flavor_enc  
 1       1         C               1
 1       2         C               1
 1       3         V               2
 2       1         S               3
 2       2         V               2
 2       3         C               1
 3       1         V               2
 4       1         C               1  
 4       2         V               2

Note: flavor_enc is showing a number, but in Stata it would show the string name in blue, which represents the number
Two issues.
When I create a variable off of the encoded, for example
g initial_pref = 0
replace initial_pref = flavor_enc if = time == 1 

OR
bysort id: egen max_pref = max(flavor_enc)

The variable first_pref takes on the encoded numeric, however, I would like to keep it in the same format as flavor_enc.
I then want to create a stacked bar chart (by flavor on the x-axis) and the frequency (on the y-axis). The chart would have one piece of the bar that represents the number of times a given flavor was someones initial preference, a second piece that represents the number of times that flavor was someone's second preference (they switched from their initial, 0 otherwise), and the last piece representing the number of times a flavor was their third preference.
For these data the chart would use these inputs. 
C as initial = 2
V as initial = 1
S as initial = 1

C as second = 0
V as second = 3
S as second = 0

C as third = 1
V as third = 0
S as third = 0

I tried graph bar with the stacking option but that did not work. I also could see how to do this outside of Stata but was hoping Stata had the functionality. 

A:

The wording is not completely clear to me, but I believe the first issue can be managed with clonevar:
clonevar initial_pref2 = flavor_enc
replace initial_pref2 = 0 if time != 1

Regarding your latest comment (and edit), if you want to compute the maximum and still use clonevar, it is possible:
clonevar max_pref2 = flavor_enc
bysort id (max_pref2): replace max_pref2 = max_pref2[_N]

If you have missings in flavor_enc, adjustments are necessary.
An alternative solution involves extracting the data attributes from the original variable using extended macro functions (help extended_fcn), and assigning them to the new variable.
One way to tackle the graph issue is as follows:
clear
set more off

*----- example data -----

input ///
id      time   str1 flavor_str     flavor  
 1       1         C               1
 1       2         C               1
 1       3         V               2
  2       3         C               1
 2       1         S               3
 2       2         V               2
 3       1         V               2
 4       2         V               2
  4       1         C               1  
end

drop flavor_str

sort id time
list, sepby(id)

*----- bar graph -----

quietly tabulate time, gen(tt)
collapse (sum) tt*, by(flavor)

label define lblflavor 1 "flavor 1" 2 "flavor 2" 3 "flavor 3"
label values flavor lblflavor

graph bar (asis) tt*, over(flavor) stack ///
    ylabel(none) blabel(bar, position(center)) legend(off)

But for sure there is a better way. I seldom use these so my experience is minimal. 
I can't say much about its appropriateness except that for this example, it seems like an awful waste of space.

